2012-01-03 78 views
1

嘗試移動上傳的文件以使其保存在目錄中,則失敗。我使用echo ($_FILES['company_logo'] ['error']);來獲取錯誤編號。我唯一可以找到的錯誤號是http://www.htmlgoodies.com/beyond/php/article.php/3472561/PHP-Tutorial-Error-Handling.htm。但是,他們的列表只能達到4,並且我得到了錯誤號6.有誰知道這個錯誤代表什麼?這裏是我的代碼:move_uploaded_file錯誤6 php

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

正如你所看到的,我做檢查的實際文件被上傳,如果文件擴展名是在允許的文件類型的列表,如果文件超過最大文件大小,路徑是否可寫。所以我不相信這是任何事情,但我不確定。任何幫助,將不勝感激。

回答

6

PHP manual知道99,99%的答案。

UPLOAD_ERR_NO_TMP_DIR

值:6;缺少臨時文件夾。在PHP 4.3.10和 PHP 5.0.3中引入。

+0

謝謝。我確實在那裏,但沒有看到一個列表。 – James 2012-01-03 22:11:00

+2

所以,鑑於這是答案,如何去解決它? – d2burke 2012-07-23 14:56:27

+2

通過在php.ini中設置正確的可寫路徑:http://www.php.net/manual/en/ini.core.php#ini.upload-tmp-dir – 2012-07-23 20:18:40

1

簡短回答:here is可能發生的所有文件上傳錯誤的列表。

你的錯誤是:

值:6;缺少臨時文件夾。在PHP 4.3.10和PHP 5.0.3中引入。

+0

謝謝。不知道爲什麼我在搜索時找不到。 dev-null-dweller先前回答了大約40秒,所以我會接受他們的答案。 – James 2012-01-03 22:12:09

+0

我發佈了我的帖子後看到了他的回答,但它完全一樣:)照你的感覺 – Geoffroy 2012-01-03 22:13:14

+0

是的,他可能會在你寫你的時候發佈他的。我只是說它發佈的時間就是全部。 – James 2012-01-03 22:16:29