在php中上传大文件

How can I upload files larger than 2MB in PHP,I searched the Internet and i changed the php.ini file,the line is: "upload_max_filesize = 200M",but I still can't upload even 2 MB file.

What seems to be the problem?

Please help me.Thanks in advance.

As you guessed, you have to set upload_max_filesize...


But you also have to set post_max_size (quoting) :

Sets max size of post data allowed.
This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize.

There are also other options which could limit this:

max_input_time = 600
php_value max_execution_time = 600
post_max_size = 200M

(...and restart Apache)

Put the following code in side the .htaccess file and save it.

php_value upload_max_filesize 200M
php_value post_max_size 200M
php_value max_input_time 2000

Try setting it with within PHP script (on top)..

ini_set("upload_max_filesize", "255M");
ini_set("post_max_size, "256M");

get your php.ini-dist file,

  • edit it to set proper values shown above
  • rename it to php.ini
  • copy it in WINDOWS directory
  • restart Apache

Once upon a time I'm facing this problem with my WAMP server, and when I search for solution, I stumbled upon to this discussion. So, if someone have the same problem, this is my working solution, I hope this help:

  1. I'm using WAMP stack. By reading your comment above, you are using WAMP stack too. In case you don't know, WAMP server has 2 (two) php.ini (in PHP directory and Apache directory) configuration, one for CLI and the other for Apache itself ( see php.ini on WAMP server ). So, I create info.php to detect which php.ini use by my server, and in my case that is the one in Apache directory ( see Which PHP Ini file does my WAMP webpage uses?).

  2. Open your php.ini that used by your server, and as @Pascal Martin suggested, change upload_max_filesizeand also set post_max_size then restart your server.

  3. Check again your info.php, make sure the value of upload_max_filesize and post_max_size has changed to your desired value.

  4. Restart Apache.

It's worked for me, hope this help.

To upload the larger file, one needs to change/increase the value of both post_max_size and upload_max_filesize directives from the php.ini file.

upload_max_filesize = 200M post_max_size = 201M

This will increase upload limits on a single file to 200 MB, from the default of 2 MB.