PHP - Uploading one or two files (large photos) works fine - uploading 5/6+ doesn't seem to even register (it just shows the upload form)
I have a page with basically this html:
<form method="post" enctype="multipart/form-data" action="photo_test.php">
<input class="fupload" name="uploadedfile[1]" type="file" />
<input class="fupload" name="uploadedfile[2]" type="file" />
<input class="fupload" name="uploadedfile[3]" type="file" />
<input class="fupload" name="uplo开发者_运维百科adedfile[4]" type="file" />
<input class="fupload" name="uploadedfile[5]" type="file" />
<input class="fupload" name="uploadedfile[6]" type="file" />
<input type=submit>
and some php to process the files. If a few (typically < 5) photos are uploaded, it works fine
if i upload 5 or 6, it doesn't seem to even register that i've uploaded files. I've tested this with adding above the code (this is on a stripped down test page to work out whats wrong).
On uploading a couple of photos it works fine (ie in the print_r($_FILES) it shows the file details. on uploading 5 or 6 of them it just prints an empty array (same as uploading nothing)
any ideas?
(this is the full script. uploading one or two images shows data in print_r($_FILES). uploading 5 or more (ish), doesn't show any data. each photo is around 2-3mb)
<?
ini_set('max_upload_filesize', 8388608);
ini_set('upload_max_filesize', 8388608);
ini_set('memory_limit', '125M');
echo "<pre>";
print_r($_FILES);
print_r($_POST);
?>
<form method="post" enctype="multipart/form-data" action="photo_test.php">
<input class="fupload" name="uploaded[1]" type="file" />
<input class="fupload" name="uploaded[2]" type="file" />
<input class="fupload" name="uploaded[3]" type="file" />
<input class="fupload" name="uploaded[4]" type="file" />
<input class="fupload" name="uploaded[5]" type="file" />
<input class="fupload" name="uploaded[6]" type="file" />
<input type=submit>
</form>
the results:
if i upload just one file
Array
(
[uploadedfile] => Array
(
[name] => Array
(
[1] => DSCN0426.JPG
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
)
[type] => Array
(
[1] => image/jpeg
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
)
[tmp_name] => Array
(
[1] => /tmp/phpNM967F
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
)
[error] => Array
(
[1] => 0
[2] => 4
[3] => 4
[4] => 4
[5] => 4
[6] => 4
)
[size] => Array
(
[1] => 2824091
[2] => 0
[3] => 0
[4] => 0
[5] => 0
[6] => 0
)
)
)
Array
(
)
if i upload several files (5 or 6)
Array
(
)
Array
(
)
PHP process the actual upload before executing your script (and fill the $_FILES global array with size and tmp path of the file), so any ini_get() or set_time_limit() call in your script would be useless.
You need to fix this in your php.ini, if you are on a shared box you need to ask to your ISP.
Also, remember to increase the 'post_max_size' value too http://www.php.net/manual/en/ini.core.php#ini.post-max-size
this error occurs when upload files's size excess the post_max_size. I meet the same problem when upload 2 large files, when I change this value, it works well. also, maybe you have to change upload_max_filesize value.
if you work on localhost, you can change php.ini easily. but when you want to change in a server as Cpanel, you can follow this http://www.webhostingzone.org/change-php-settings.html
What's your php.ini's post_max_size? You have to adjust this value as well (8MB by default), that's why your $_POST array is empty.
EDIT: upload_max_filesize and post_max_size can't be changed using ini_set because their changeable state is set to PHP_INI_PERDIR (see http://be2.php.net/manual/en/ini.list.php) It should be PHP_INI_USER.
So, you obvisouly stick to the default values (probably 2M and 8M) hence the empty $_FILES.
You have to change these options using the server config (php.ini or apache conf) or a .htaccess file. See http://php.net/manual/en/configuration.changes.php
It is possible the script is timing out. You should try uploading 6 very small files and/or look into set_time_limit()
精彩评论