move_uploaded_file错误6 php [英] move_uploaded_file error 6 php

查看:176
本文介绍了move_uploaded_file错误6 php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $'$'''''。'jpeg','。gif',' .BMP, 'PNG')。 //这些将是通过验证的文件的类型。
$ max_filesize = 524288; // BYTES中的最大文件大小(目前为0.5MB)。
$ upload_path ='../images/companies/'; //文件将被上传到的位置(当前是文件目录)。
$ b $ if($ _ FILES ['company_logo'] ['name']!=){
if($ row ['image']!=''){
unlink(../\".$ row ['image']);
}

$ filename = $ _FILES ['company_logo'] ['name']; //获取文件的名称(包括文件扩展名)。
$ ext = substr($ filename,strpos($ filename,'。'),strlen($ filename)-1); //从文件名获得扩展名
$ ext = strtolower($ ext);
//检查文件类型是否被允许,如果不是DIE并通知用户。
if(!in_array($ ext,$ allowed_filetypes))
die('您试图上传的文件是不允许的。

//现在检查文件大小,如果它太大,那么DIE并通知用户。
if(filesize($ _ FILES ['company_logo'] ['tmp_name'])> $ max_filesize)
die('您尝试上传的文件太大。

//检查是否可以上传到指定的路径,如果不是DIE并通知用户。
if(!is_writable($ upload_path))
die('您不能上传到指定的目录,请将其改为777.');

//将文件上传到指定的路径。
$ ran = rand();
$ filename = $ ran。$ ext;
if(move_uploaded_file($ _ FILES ['company_logo'] ['tmp_name'],$ upload_path。$ filename)){//这是失败的地方
$ file = $ upload_path。$ filename;

$ result = mysql_query(UPDATE Companies SET image ='images / companies / $ filename'WHERE id ='$ id';);
$ b $ if($ result)
$ _SESSION ['message']。=< p class ='copy'style ='color:red;'>您的图片上传成功< / p>中; // 有效。
else
$ _SESSION ['message']。=< p class ='copy'style ='color:red;'>无法上传图片< / p> ;
} else {
$ _SESSION ['message']。=< p class ='copy'style ='color:red;'>无法上传图片< p>中;
echo($ _FILES ['company_logo'] ['error']);
die();




$ b $你可以看到,如果文件扩展名在允许的文件类型列表中,文件超过最大文件大小以及路径是否可写,则上传文件。所以我不相信这是什么东西,但是我不确定。任何帮助将不胜感激。

解决方案

知道99,99%的答案。

lockquote
UPLOAD_ERR_NO_TMP_DIR

strong>



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



Attempting to move an uploaded file so that it is saved in the directory, it fails. I use echo ($_FILES['company_logo'] ['error']); to get the error number. The only place I could find with error numbers for this was http://www.htmlgoodies.com/beyond/php/article.php/3472561/PHP-Tutorial-Error-Handling.htm . However, their list only goes up to 4 and I am getting the error number 6. Does anyone know what this error stands for? Here is my code:

$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();
    }
}

As you can see, I do check for an actual file being uploaded, if the file extension is in a list of file types allowed, if the file exceeds the max file size, and whether the path is even writable. So I don't believe it is any of those things, but I'm not certain. Any help would be appreciated.

解决方案

PHP manual knows 99,99% answers.

UPLOAD_ERR_NO_TMP_DIR

Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.

这篇关于move_uploaded_file错误6 php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆