2011-02-15 124 views
0

我有一個表單上傳2個文件。他們可以上傳一個,或者同時上傳兩個。 當我上傳兩個小圖像文件(都在100kb以下)時,它們工作得很完美。但是如果一個文件比較大,比如大約200kb,那麼這個文件不起作用。我已經在下面的隱藏標記中將最大值設置爲「100000」,所以我不確定我還能做些什麼來解決這個問題?PHP上傳表單 - 無法上傳200kb圖像文件

<form enctype="multipart/form-data" action="upload.php" method="post">  
<b>Image File</b><br /> 
<input type="hidden" name="MAX_FILE_SIZE" value="100000" /> 

<b>Large Image</b>: <input type="file" name="uploadedfile1" size="30" /><br /> 

<b>Thumb Image</b>: <input type="file" name="uploadedfile2" size="30" /><br /> 

<center><input type="submit" name="submit" value="submit" class="button"></center> 

</form> 

當它的處理,它關係到這個PHP代碼:

$uploadedfileBase1 = basename($_FILES['uploadedfile1']['name']); 
$uploadedfileTemp1 = $_FILES['uploadedfile1']['tmp_name']; 
$uploadedfileBase2 = basename($_FILES['uploadedfile2']['name']); 
$uploadedfileTemp2 = $_FILES['uploadedfile2']['tmp_name']; 


// Large Image 
$target_path_large = $target_path . "large/" . $uploadedfileBase1; 

if(move_uploaded_file($uploadedfileTemp1, $target_path_large)) { 
echo "<p>The <b>large</b> file \"$uploadedfileBase1\" has been uploaded.</p>"; 
} else{ 
echo "<p>There was an error uploading the <b>large</b> file <i>$uploadedfileBase1</i>, please try again!</p>"; 
} 

// Thumb Image 
$target_path_thumb = $target_path . "thumbs/" . $uploadedfileBase2; 

if(move_uploaded_file($uploadedfileTemp2, $target_path_thumb)) { 
echo "<p>The <b>thumbnail</b> file \"$uploadedfileBase2\" has been uploaded.</p>"; 
} else{ 
echo "<p>There was an error uploading the <b>thumbnail</b> file <i>$uploadedfileBase2</i>, please try again!</p>"; 
} 

感謝您的閱讀!

+0

我剛剛檢查了我的php.ini,並發現以下值(我認爲這些值都很慷慨,因此可能不是原因..?):post_max_size(8M),upload_max_filesize(2M),max_execution_time(30 ),max_input_time(60),memory_limit(24M) – Jay 2011-02-15 04:02:05

回答

4

你應該在你的服務器檢查php.ini文件中,特別是以下參數:

  1. 的post_max_size

  2. 的upload_max_filesize

  3. 的max_execution_time

  4. max_input_time設置

  5. memory_limit的

在你的情況,也許對太小的post_max_size & upload_max_filesize的問題。

編輯:現在我注意到,你自己在隱藏字段中定義MAX_FILE_SIZE = 100000字節< 100 KB。所以你的上傳文件肯定不能超過100KB。如果你想上傳更大的文件,你必須增加這個值。

1

隱藏表單域標記是瀏覽器的建議,這是允許的最大大小,但不會更改服務器端設置。對您的文件進行任何處理之前,你必須檢查是否上傳成功:

if ($_FILES['uploadedfile1']['error'] !== UPLOAD_ERR_OK) { 
    die("file #1 failed with error code " . $_FILES['uploadedfile1]['error']); 
} 

等。文件上傳錯誤常量的完整列表可用here

想象一下,如果該隱藏字段允許您覆蓋服務器大小限制 - 即使您將限制設置爲10兆字節,也不會阻止某人上傳太字節大小的文件?

+0

嗯,我得到失敗的錯誤,但我不知道爲什麼...當我通過FTP檢查時,大文件沒有上傳,但較小的文件沒有。 – Jay 2011-02-15 04:07:15

+0

那麼錯誤代碼是什麼? – 2011-02-15 14:13:18