我正在做一个文件上传页面,它将在添加文件之前重命名该文件,并且出现了这些错误。
我已经在网站的文件夹中尝试过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上可以正常使用
答案 0 :(得分:0)
尝试
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.";
}
答案 1 :(得分:0)
您必须使用绝对路径 喜欢
[Locations]
# Path to loadout config. Can use relative path from here.
looks_config = ./app.cfg
# Path to python file. Can use relative path from here.
python_file = ./Derevo.py
# Name of the bot in-game
name = NV Derevo
[Details]
# These values are optional but useful metadata for helper programs
# Name of the bot's creator/developer
developer = The RLBot community
# Short description of the bot
description = This is a description
# Fun fact about the bot
fun_fact =
# Link to github repository
github = https://github.com/RLBot/RLBotPythonExample
# Programming language
language = python