move_uploaded_file PHP错误
您好,我正在尝试通过表单将用户在本地计算机上选择的文件上传到我的服务器,但出现以下 php 错误:
警告:move_uploaded_file(bqformtest/uploaded_files/test.doc) [function.move-uploaded-file]:无法打开流:没有这样的文件或 在线 /home/drawapl1/public_html/bqformtest/index.php 目录 40
警告:move_uploaded_file() [function.move-uploaded-file]:无法 将“/tmp/phphhS4QD”移动到“bqformtest/uploaded_files/test.doc” /home/drawapl1/public_html/bqformtest/index.php 第 40 行
这是我的 php 代码:
$target = "bqformtest/uploaded_files/";
$target = $target . basename( $_FILES['upload']['name']) ;
if(move_uploaded_file($_FILES['upload']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
这是我的表单代码:
<form method='post' action='' accept-charset='UTF-8' enctype='multipart/form-data'>
<input type="file" name="upload" size="50" />
<input id="submitButton" type='submit' name='Submit' value='' />
</form>
uploaded_files 文件夹权限设置为 755。提前致谢。
Hello I am trying to upload a file a user selects on their local computer to my server through a form but I get the following php error:
Warning: move_uploaded_file(bqformtest/uploaded_files/test.doc)
[function.move-uploaded-file]: failed to open stream: No such file or
directory in /home/drawapl1/public_html/bqformtest/index.php on line
40Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
move '/tmp/phphhS4QD' to 'bqformtest/uploaded_files/test.doc' in
/home/drawapl1/public_html/bqformtest/index.php on line 40
This is my php code:
$target = "bqformtest/uploaded_files/";
$target = $target . basename( $_FILES['upload']['name']) ;
if(move_uploaded_file($_FILES['upload']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
This is my form code:
<form method='post' action='' accept-charset='UTF-8' enctype='multipart/form-data'>
<input type="file" name="upload" size="50" />
<input id="submitButton" type='submit' name='Submit' value='' />
</form>
The uploaded_files folders permissions is set to 755. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
提供文件的完整路径,或正确的相对路径
文件的路径是错误的
Provide full path to file, or right relative path
the path to file is wrong
根据错误消息我可以看出,您的脚本位于
ROOT/bqformtest
中。然后将$target
设置为相对路径:bqformtest/uploaded_files
。这意味着脚本将尝试将上传的文件从临时目录移动到:ROOT/bqformtest
+bqformtest/uploaded_files
,结果是:ROOT/bqformtest/bqformtest/ uploaded_files
。将$target
设置为:或
它应该可以工作。
顺便说一句,您正在使用上传文件的名称而不对其进行清理,这是一个重大的安全风险。不要相信用户发送的任何内容。
From what I can tell based on the error message, your script is in
ROOT/bqformtest
. Then you are setting$target
to relative path:bqformtest/uploaded_files
. This means the script will try to move the uploaded file from the temp dir to:ROOT/bqformtest
+bqformtest/uploaded_files
resulting in:ROOT/bqformtest/bqformtest/uploaded_files
. Set$target
to:or
and it should work.
By the way, you are using the name of the uploaded file without sanitizing it which is a major security risk. Don't trust anything sent by the user.
另请检查用户的磁盘配额。我遇到了这个问题,经过几个小时的测试,我发现这很简单。超出用户配额
Also Check disk quota for the user. I had this problem and and after many hours of testing I found it was simple. The user's quota was exceeded