move_uploaded_file PHP错误

发布于 2024-12-10 08:47:50 字数 1200 浏览 0 评论 0原文

您好,我正在尝试通过表单将用户在本地计算机上选择的文件上传到我的服务器,但出现以下 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
40

Warning: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

娜些时光,永不杰束 2024-12-17 08:47:50

提供文件的完整路径,或正确的相对路径

$target = "{fullPath}/fileName"; 

文件的路径是错误的

Provide full path to file, or right relative path

$target = "{fullPath}/fileName"; 

the path to file is wrong

复古式 2024-12-17 08:47:50

根据错误消息我可以看出,您的脚本位于 ROOT/bqformtest 中。然后将 $target 设置为相对路径:bqformtest/uploaded_files。这意味着脚本将尝试将上传的文件从临时目录移动到:ROOT/bqformtest + bqformtest/uploaded_files,结果是:ROOT/bqformtest/bqformtest/ uploaded_files。将 $target 设置为:

$target = "uploaded_files/";

$target = "/home/drawapl1/public_html/bqformtest/uploaded_files/";

它应该可以工作。

顺便说一句,您正在使用上传文件的名称而不对其进行清理,这是一个重大的安全风险。不要相信用户发送的任何内容。

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:

$target = "uploaded_files/";

or

$target = "/home/drawapl1/public_html/bqformtest/uploaded_files/";

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.

有深☉意 2024-12-17 08:47:50

另请检查用户的磁盘配额。我遇到了这个问题,经过几个小时的测试,我发现这很简单。超出用户配额

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文