I currently have the following:
if (in_array($_FILES['userfile']['type'], $mimeTypes))
{
$target_path = "./uploads/{$_SESSION['email']}";
$target_path = $target_path . basename( $_FILES['userfile']['name']);
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['userfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
When someone creates a login, a directory is created for the user using their email, 0666 permission.
Currently, the move_uploaded_file() places the file just oustide of the user’s directory, inside the uploads directory. The error is being thrown. I’ve checked many times that my relative path is correct.
I’m using Ubuntu and the uploaded file has a Lock symbol on it, but lets me drag and drop into the user’s folder.
Your
$target_pathappears to be missing a/following the user’s directory, sincebasename()‘s output won’t include a/.The correct permissions for a directory should be
0755(you don’t want it world-writable!), as directories should have execute permissions to be traversed by the filesystem. You can make it group-writable (0775) and make sure the upload directories have their group set to the Apache web server user. This would be best done by setting setgid on the uploads/ directory and setting its group to the apache user so use directories created beneath it inherit the correct write permissions without being world-writable.