I am doing a file upload page , that will rename the file before adding it , and i am getting those errors.
I’ve tried chmod -R 777 ./
in the folder of the website but it still doesn’t work.
$dir = Users::currentUser()->id;//each user have his folder
if(move_uploaded_file($_FILES["file"]["tmp_name"], PROOT . 'files' . DS . $dir . DS))
{
echo "The file has been uploaded as ".$ran2.$ext;
//Router::redirect('upload');
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
The PROOT
is defined by me as the website root folder define('PROOT','/framework/');
and the DS
is the separator (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? define('DS', '/') : define('DS', DIRECTORY_SEPARATOR);
.
And this is how the error looks
Warning: move_uploaded_file(/framework/files/4/): failed to open stream: No such file or directory in /opt/lampp/htdocs/framework/app/controllers/UploadController.php on line 46
Warning: move_uploaded_file(): Unable to move '/opt/lampp/temp/phpHz70FG' to '/framework/files/4/' in /opt/lampp/htdocs/framework/app/controllers/UploadController.php on line 46
And i am also getting the error from the if
statement
Sorry, there was a problem uploading your file.
And here is a picture of my files structure
Update
The problem were cause of ubuntu permissions , on windows it works perfect
2
Answers
try it
you have to use absolute path
like