简体   繁体   中英

How can I prevent large Apache/PHP file uploads from failing?

I recently installed a PHP download portal on one of our servers. Everything is working fine, but users can't upload large files (~ 20 MB).

I set the following settings to extremely large values or unlimited:

memory_limit
upload_max_filesize
post_max_size
memory_limit

Full php.ini here: http://pastebin.com/NrqJvMVM

But it still fails after restarting the server.

Am I missing a setting? Do I have to update any values in the Apache configuration? Could a company firewall somehow interfere with that?

EDIT: I checked phpinfo() and the master configuration still shows the old values. The config file C:\\Windows\\php.ini however, has the new values. Am I using the wrong config file.

You can test the params in a script, too. Perhaps this helps:

  1. max_execution_time = ini_set("max_execution_time", "-1");
  2. post_max_size = ini_set("post_max_size", "200M");
  3. memory_limit = ini_set("memory_limit", "200M");
  4. upload_max_filesize = ini_set("upload_max_filesize", "200M");

In .htaccess:

php_value upload_max_filesize 200M

php_value memory_limit 256M

php_value max_execution_time 18000

Here are nice articles about this topic: http://www.cyberciti.biz/faq/linux-unix-apache-increase-php-upload-limit/ | https://www.dokuwiki.org/faq:uploadsize

Is Suhosin installed on your server or do you use fcgi ;-)?

All the configuration settings for your installation are contained in the php.ini file . Sometimes these setting might be overridden by directives in apache .htaccess files or even with in the scripts themselves.

Following settings that we need to modify -

  • file_uploads
  • upload_max_filesize
  • max_input_time
  • memory_limit
  • max_execution_time
  • post_max_size

The configuration settings in detail below.

  • upload_max_filesize and post_max_size

    Files are usually POSTed to the webserver in a format known as 'multipart/form-data'. The post_max_size sets the upper limit on the amount of data that a script can accept in this manner. Ideally this value should be larger than the value that you set for upload_max_filesize.

    It's important to realize that upload_max_filesize is the sum of the sizes of all the files that you are uploading. post_max_size is the upload_max_filesize plus the sum of the lengths of all the other fields in the form plus any mime headers that the encoder might include. Since these fields are typically small you can often approximate the upload max size to the post max size.

    According to the PHP documentation you can set a MAX_UPLOAD_LIMIT in your HTML form to suggest a limit to the browser.

  • memory_limit

    When the PHP engine is handling an incoming POST it needs to keep some of the incoming data in memory. This directive has any effect only if you have used the --enable-memory-limit option at configuration time. Setting too high a value can be very dangerous because if several uploads are being handled concurrently all available memory will be used up and other unrelated scripts that consume a lot of memory might effect the whole server as well.

  • max_execution_time and max_input_time

    These settings define the maximum life time of the script and the time that the script should spend in accepting input. If several mega bytes of data are being transfered max_input_time should be reasonably high. You can override the setting in the ini file for max_input_time by calling the set_time_limit() function in your scripts.

Additonal Comments

  • Apache Settings

    The apache webserver has a LimitRequestBody configuration directive that restricts the size of all POST data regardless of the web scripting language in use. Some RPM installations sets limit request body to 512Kb. You will need to change this to a larger value or remove the entry altogether.

  • Other Options

    If you expect to handle a large number of concurrent file transfers on your website consider using a perl or java server side component. PHP happens to be our favourite web programming language as well but perl and Java are just slightly ahead when it comes to file upload.

See also:

  1. Upload large File upto 100MB using php
  2. upload large files using php, apache
  3. PHP: Uploading large files fail

Maybe, this article can help you. You can add params to .htaccess

你已经写了两次post_max_size变量,如果0和第二个值是9999M,则从第一个值开始,删除第一个并尝试它。

Am I using the wrong config file.

Well, phpinfo() tells you which one you are using. Look at Configuration File (php.ini) Path and Loaded Configuration File right near the top of the output.

Maybe MAX_FILE_SIZE is not properly set...

<form enctype="multipart/form-data" action="index.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
<input name="filedata" type="file" />
<input type="submit" value="Send file" />
</form>

你应该找到正确的php.ini文件=)

I have been in your situation in the past and the best solution I found was using third party library to split the files into chunks on the client side and put it all back together on the server. I found this: http://www.plupload.com/

Very handy and effective. It works with a variety of different technologies so it can work on a wide majority of clients machines. (flash, silverlight, html5 file api aso...) Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM