0

i have the form, and i want to upload two files. here is the script

<form action="form.php" method="post" enctype="multipart/form-data" />
<input type="file" name="video"  />
<input type="file" name="picture" >
<input type="submit"  class="input" value="Հիշել" />
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
</form>

form.php:

<?
    print_r($_FILES);
    $video_name = $_FILES["video"]["name"];
    $image_name = $_FILES["picture"]["name"];
    echo "video",$video_name;
    echo "image",$image_name;
                              //returns Array ( ) videoimage
?>

when i try to upload the file greater than 10MB, it doesn't happen. i try in many browsers. maybe i must change some field in php.ini? but i haven't permission to change them on the server. so what can i do? thanks

Simon
  • 22,637
  • 36
  • 92
  • 121

2 Answers2

7

File Uploads - Common Pitfalls

The MAX_FILE_SIZE item cannot specify a file size greater than the file size that has been set in the upload_max_filesize in the php.ini file. The default is 2 megabytes.

If a memory limit is enabled, a larger memory_limit may be needed. Make sure you set memory_limit large enough.

...

If post_max_size is set too small, large files cannot be uploaded. Make sure you set post_max_size large enough.

You can increase the value for MAX_FILE_SIZE three four ways:

1) php.ini

upload_max_filesize = 20M
post_max_size = 20M

2) ini_set()

ini_set('upload_max_filesize', 20M);
ini_set('post_max_size', 20M);

3) .htaccess

php_value upload_max_filesize 20M
php_value post_max_size 20M

4) hidden form fields

<input name="MAX_FILE_SIZE" value="20971520" type="hidden">
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • @John Conde is there any function to do this( like ini_set())? – Simon Apr 09 '10 at 16:29
  • MAX_FILE_SIZE is only a HINT for your browser and does not specify the limit PHP accepts for file uploads. – Robert Apr 09 '10 at 16:29
  • @Robert: The browser doesn't understand `MAX_FILE_SIZE` as anything but a form field. It's PHP that uses this value, but it can't override the ini setting. – Powerlord Apr 09 '10 at 17:25
  • @John Conde thanks much:) and what is the highest limit of that size? – Simon Apr 09 '10 at 17:52
  • @Syom, It's whatever you want it to be (assuming you have control over server settings). On my dedicated server it is set to 100M since we have clients who upload large files. – John Conde Apr 09 '10 at 18:15
  • @John Conde hmmmmmmm:( i've set the max_size 200M, but i can't upload greater than 55M. i also set ini_set('max_execution_time', "900"); – Simon Apr 09 '10 at 18:40
  • @Syom Some other setting might be limited to 55M. phpinfo() should show you all of the ini settings and what there values are. – John Conde Apr 09 '10 at 18:52
  • @John Conde yes, when i print phpinfo() it shows, that post_max_size is 64MB, but i set 400MB. could you tell me how it happens? thanks much John – Simon Apr 09 '10 at 18:57
  • As I noted elsewhere, you can not use ini_set with these directives as they are marked `PHP_INI_PERDIR`. – Powerlord Apr 09 '10 at 19:29
  • @UNICORNS: I just checked http://php.net/manual/en/features.file-upload.post-method.php against http://php.net/manual/de/features.file-upload.post-method.php and the german translation says "MAX_FILE_SIZE" is a hint for the browser whereas the english original refers about a PHP 1st-level-check for file uploads. – Robert Apr 10 '10 at 03:17
  • @all. I checked PHP source for MAX_FILE_SIZE to be sure:http://stackoverflow.com/questions/1381364/max-file-size-in-php-whats-the-point/6273418#6273418 – Stann Jun 08 '11 at 02:15
1

In your php.ini, adjust the upload_max_filesize directive. Also set the memory_limit to a higher number.

jweyrich
  • 31,198
  • 5
  • 66
  • 97