2011-02-15 74 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