我正在做一个文件上传页面,它会在添加文件之前重命名该文件,并且我收到了这些错误。我在网站的文件夹中尝试过chmod -R 777 ./
,但它仍然无法正常工作。
$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.";
}
PROOT
被我定义为网站根文件夹define('PROOT','/framework/');
,而DS
是分隔符(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? define('DS', '/') : define('DS', DIRECTORY_SEPARATOR);
。
这就是错误的样子
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
我也从if
声明中得到错误
Sorry, there was a problem uploading your file.
而here是我的文件结构的图片
更新
问题是ubuntu权限的原因,在Windows上它完美无缺
试试吧
define('PROOT','framework/');
(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? define('DS', '/') : define('DS', DIRECTORY_SEPARATOR)
$dir = Users::currentUser()->id;//each user have his folder
$path = PROOT . 'files' . DS . $dir . DS;
if(move_uploaded_file($_FILES["file"]["tmp_name"],$path)
{
echo "The file has been uploaded as ".$ran2.$ext;
//Router::redirect('upload');
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
你必须使用绝对路径
define('PROOT','/opt/lampp/htdocs/framework/');