【问题标题】:move_uploaded_file error 6 phpmove_uploaded_file 错误 6 php
【发布时间】:2012-01-03 22:02:16
【问题描述】:

尝试移动上传的文件以将其保存在目录中,但失败。我使用echo ($_FILES['company_logo'] ['error']); 来获取错误号。我能找到的唯一错误编号是 http://www.htmlgoodies.com/beyond/php/article.php/3472561/PHP-Tutorial-Error-Handling.htm 。但是,他们的列表最多只有 4 个,我得到的错误号是 6。有谁知道这个错误代表什么?这是我的代码:

$allowed_filetypes = array('.jpg','.jpeg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
$max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
$upload_path = '../images/companies/'; // The place the files will be uploaded to (currently a 'files' directory).

if($_FILES['company_logo']['name'] != "") {
    if($row['image'] != ''){
        unlink("../".$row['image']);
    }

    $filename = $_FILES['company_logo']['name']; // Get the name of the file (including file extension).               
    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
    $ext = strtolower($ext);
    // Check if the filetype is allowed, if not DIE and inform the user.
    if(!in_array($ext,$allowed_filetypes))
        die('The file you attempted to upload is not allowed.');

    // Now check the filesize, if it is too large then DIE and inform the user.
    if(filesize($_FILES['company_logo']['tmp_name']) > $max_filesize)
        die('The file you attempted to upload is too large.');

    // Check if we can upload to the specified path, if not DIE and inform the user.
    if(!is_writable($upload_path))
        die('You cannot upload to the specified directory, please CHMOD it to 777.');

      // Upload the file to your specified path.
    $ran = rand();
    $filename = $ran.$ext;
    if(move_uploaded_file($_FILES['company_logo']['tmp_name'],$upload_path.$filename)){  // This is where it fails
           $file = $upload_path.$filename;

           $result = mysql_query("UPDATE Companies SET image = 'images/companies/$filename' WHERE id = '$id';");                                                        

           if($result)
              $_SESSION['message'] .= "<p class='copy' style='color:red;'>Your image upload was successful.</p>"; // It worked.
           else
              $_SESSION['message'] .= "<p class='copy' style='color:red;'>Unable to upload image(s).</p>";
    }else{
           $_SESSION['message'] .= "<p class='copy' style='color:red;'>Unable to upload image(s).</p>";
           echo ($_FILES['company_logo'] ['error']);
            die();
    }
}

如您所见,我确实会检查正在上传的实际文件、文件扩展名是否在允许的文件类型列表中、文件是否超过最大文件大小以及路径是否可写。所以我不相信这是任何事情,但我不确定。任何帮助将不胜感激。

【问题讨论】:

    标签: php file-upload


    【解决方案1】:

    PHP manual 知道 99.99% 的答案。

    UPLOAD_ERR_NO_TMP_DIR

    值:6;缺少一个临时文件夹。在 PHP 4.3.10 和 PHP 5.0.3。

    【讨论】:

    【解决方案2】:

    简答:here is 可能发生的所有文件上传错误的列表。

    你的错误是:

    值:6;缺少一个临时文件夹。在 PHP 4.3.10 和 PHP 5.0.3 中引入。

    【讨论】:

    • 谢谢。不知道为什么我在搜索时找不到。不过,dev-null-dweller 大约在 40 秒前回答了,所以我将接受他们的答案。
    • 我在发布我的帖子后看到了他的回答,但它完全一样:) 随心所欲
    • 是的,他可能在你写你的时候发布了他的。我只是离开它说它已发布的时间而已。
    猜你喜欢
    • 2011-03-30
    • 2011-12-08
    • 2023-03-23
    • 2011-02-06
    • 2017-09-11
    • 2013-06-12
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    相关资源
    最近更新 更多