So I'm having an issue. When someone signs up for an account on the site I'm building, they go to a setup page where they can upload a profile picture. I'm using mkdir to auto create a sub-folder with their username which is working fine, and CHMOD is 777 on that sub folder. The problem I'm having is that image is not being moved to that specified sub-folder, but it's going into the "uploads" folder which is it's parent directory.
Hopefully I haven't confused anyone, but I'm really needing help.
Below is my script I wrote to do this.
===============================================================================
require_once('../admin/includes/config.php');
$uploaded_file = $_REQUEST['uploaded_file'];
$member_id = $_REQUEST['member_id'];
$name = $_REQUEST['name'];
$location = $_REQUEST['location'];
$hobbies = $_REQUEST['hobbies'];
$hobby = $_REQUEST['hobby'];
// using member_id, extract the username from the members table so we can auto create a sub-directory for the images
$result = mysql_query("SELECT username FROM members WHERE member_id = '$member_id'");
while($row = mysql_fetch_array($result))
{
$username = $row['username'];
}
// unmask to change CHMOD of newly created sub directory to 777
$old_mask = umask(0);
//Create directory with member's username
$madedir = mkdir('../admin/uploads/'.$username.'', 0777) /*== TRUE ? 1 : 0*/;
umask($old_mask);
// Assign the directory the file is going to be uploaded to
$uploaddir = '../admin/uploads/'.$username.'';
// Get the file name
$file_name = $_FILES['uploaded_file']['name'];
// Upload file to assigned directory with file name
$uploadfile = $uploaddir . basename($_FILES['uploaded_file']['name']);
// If the file has been uploaded, run this script
if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $uploadfile)) {
echo "Success";
} // end if
else {
echo "there was an error uploading your file";
}