2012-01-03 6 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 error 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

+2

これは答えだとしたら、それを修正する方法は? – d2burke

+2

正しい書き込み可能パスをphp.iniに設定することによって:http://www.php.net/manual/en/ini.core.php#ini.upload-tmp-dir –

1

短い回答:here is発生するすべてのファイルアップロードエラーのリスト。

あなたのエラーは、次のとおりです。

値:6;一時フォルダがありません。 PHP 4.3.10およびPHP 5.0.3で導入されました。

+0

ありがとう。なぜ私はそれを見つけることができなかったのか分からない。 dev-null-dwellerは約40秒前に答えましたので、私は答えとしてそれらを受け入れるつもりです。 – James

+0

私は自分の投稿後に彼の答えを見ましたが、それは全く同じです:)あなたが感じるようにしてください – Geoffroy

+0

ええ、彼はおそらくあなたの書いたとおりに投稿しました。私はそれが掲示されたと言っている時間はすべてです。 – James