5

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.

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
xsl
  • 17,116
  • 18
  • 71
  • 112

8 Answers8

14

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 ;-)?

chris
  • 1,245
  • 1
  • 10
  • 22
  • I don't use Suhoshin or fcgi. I tried to add the values to .htaccess, but the file upload still doesn't work. I don't get an error message now, but the file never appears on the server. – xsl Aug 02 '12 at 14:30
  • I edited the question, maybe the additional information will help you. – xsl Aug 02 '12 at 14:42
  • It's working now. For some reason php could not read the config file in the windows directory. – xsl Aug 02 '12 at 15:02
6

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
Community
  • 1
  • 1
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
  • Thank you for your insightful answers, I hope it gets the upvotes it deserves. Unfortunately I have already solved the problem a few days ago and accepted an answer that helped me doing so. – xsl Aug 07 '12 at 09:06
  • No issues. I have given answer thoroughly because current answers were not giving much information. – Somnath Muluk Aug 07 '12 at 09:13
3

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

Kerberos
  • 1,228
  • 6
  • 24
  • 48
  • Thanks, but I believe I have all those settings set. – xsl Jul 06 '12 at 11:27
  • When i was working on huge uploads, i found this applet http://jumploader.com/ That can use php too. Maybe this can be good for your project. – Kerberos Jul 06 '12 at 11:38
2

You have written post_max_size variable twice and out of which value of first if 0 and value of second is 9999M, remove the first one and try it.

Ravinder Singh
  • 3,113
  • 6
  • 30
  • 46
  • Tried it, but it didn't help. – xsl Jul 06 '12 at 11:31
  • why did you increase the value of these variables so much, just set them according to your needs, not more than that. – Ravinder Singh Jul 06 '12 at 11:36
  • The only value that is really huge is the file upload size (9999 MB). I need an unlimited upload size, but 9999 MB is enough. – xsl Jul 06 '12 at 11:41
  • May i know What are you allowing the users to upload. – Ravinder Singh Jul 06 '12 at 11:42
  • It's used by close customers to upload files that can't be transmitted by email, because they are either too large or because a security service is blocking it (e.g. some companies are not allowing you to send executables) – xsl Jul 06 '12 at 11:48
2

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 Fileright near the top of the output.

1

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>
milan-j
  • 619
  • 7
  • 15
  • The download portal has been working on other servers, so I think the problem is not caused by the code itself. – xsl Jul 06 '12 at 11:28
1

You should find correct php.ini file =)

el Dude
  • 5,003
  • 5
  • 28
  • 40
1

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!

Armel Larcier
  • 15,747
  • 7
  • 68
  • 89
  • Great example of how to handle this + full code download: http://webdev-blog.com/ajax-upload-script-with-custom-folders/ – m1crdy May 27 '15 at 09:43