【问题标题】:move_uploaded_file php errormove_uploaded_file php错误
【发布时间】:2011-12-08 19:43:26
【问题描述】:

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

upload_files 文件夹权限设置为 755。提前致谢。

【问题讨论】:

  • upload_files 目录的所有者是什么?

标签: php upload


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    根据错误消息我可以判断,您的脚本位于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/";
    

    它应该可以工作。

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

    【讨论】:

      【解决方案3】:

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

      $target = "{fullPath}/fileName"; 
      

      文件路径错误

      【讨论】:

      • 如果我将这行代码中的路径更改为$target = "home/drawapl1/www/bqformtest/uploaded_files/";,我会收到相同的错误消息。我认为这就是完整的路径。
      • @Ben Paton:完整路径必须以/开头
      • 谢谢只是缺少开头 / :)
      • @Ben Paton:另一件事 - 您的脚本容易受到攻击。详情见我的回答。
      猜你喜欢
      • 2011-03-30
      • 1970-01-01
      • 2023-03-23
      • 2011-02-06
      • 2017-09-11
      • 2013-06-12
      • 1970-01-01
      • 1970-01-01
      • 2015-10-01
      相关资源
      最近更新 更多