Change the maximum upload size with PHP

Depending on how you host your website (or application) there are different ways to change the PHP settings. In particular, the most asked about problem, changing the maximum upload size.

There are 3 settings PHP uses that limit your uploading ability:

post_max_size
This is the combined maximum size of all files sent on the form. If you have 2 file fields on your form, the total filzesize of the 2 files must not exceed the post_max_size value.
upload_max_filesize
This is the filesize limit of each individual file.
memory_limit
PHP scripts have a memory limit, and generally speaking this can prevent some uploads from working. The limit should be set at a reasonable level, of course you won’t need 20mb for a simple ‘hello world’ script. Try slowly increasing this value if you find that uploads still aren’t working.

If you host your site remotely, you should check their documentation on how to change the PHP configuration settings. But if you’re not so inclined, and prefer a trial and error approach, here’s a summary of things to try:

Change php.ini directly

If you host your site on a server that you have access to, you can change your php.ini file directly. This is the easiest approach. Your php.ini file should exist in the PHP installation directory. Open it in your favourite text editor and search for these lines and change them:

memory_limit = 8M
post_max_size = 8M
upload_max_filesize = 2M

You may need to restart apache for the changes to take effect.

Changes to .htaccess

.htaccess files only apply to Apache webservers. They are files that append and change certain values that apache uses and they are placed in the root folder (and all folders beneath will use those settings). If apache uses PHP as a Module, then you can add values to the .htaccess file:

php_flag file_uploads On
php_value memory_limit 8M
php_value post_max_size 8M
php_value upload_max_filesize 2M
 

Download this code: .htaccess.txt

If you try this approach, and your webserver displays a 500 interal server error, then PHP is not runing as a module and apache didn’t like the php_value entries. You will need to remove your changes.

Upload a php.ini file

This generally works if the changes to .htaccess method doesn’t. Some web hosts that use apache, also use PHP as a CGI. Then also, most times, this allows changes to the PHP configuration using a custom php.ini file that you can upload. You don’t want to include every setting available to PHP in your file. Only include the ones you want to change, and don’t forget the heading [PHP]:

[PHP]
; Whether to allow HTTP file uploads.
file_uploads = On
; Maximum amount of memory a script may consume (8MB)
memory_limit = 8M
; Maximum size of POST data that PHP will accept.
post_max_size = 8M
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M 

Download this code: php.ini

Still not working

In the event these techniques didn’t work for you, check with your host’s documentation.


Share this Post:
Digg del.icio.us Facebook Google Bookmarks StumbleUpon Slashdot

written by Luca March 2nd, 2008 at 10:12 | #1

your ajax file browser site is down, also could you make a remember login button please :)


written by jc March 4th, 2008 at 09:43 | #2

Yep that’s right. Production has fallen over. You can still download the latest version from:
http://sourceforge.net/project/showfiles.php?group_id=193937

And sorry, I won’t be doing any more work on this application.


written by Daniel Morante March 7th, 2008 at 03:52 | #3

Your Ajax File Browser is a great application. To show my thanks, I submitted a small patch that will add a “browse” button when adding or editing a share.


written by maurits April 8th, 2008 at 04:44 | #4

check my website http://old-dutch.net i got a upload steem but i can only upload 2mb and i did change the php.ini but noting heppends help!!!!


written by maurits April 8th, 2008 at 04:45 | #5

OMG NVM ITS WORK THANKS DUDE1!


written by Ali May 27th, 2008 at 04:07 | #6

Hi

This application is awesome, easy to use and is exactly what I need. However it seems like for larger files the download cuts out after 60sec regardless of how much of the file has been downloaded. I think this has to do with the following in PHP.ini:

max_execution_time = 60 ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data

I have tried changing these values and increasing them to 90sec, and higher, however it does not seem to solve the issue. Is AJAX File Browser still supported by any communities? is there anyone who can help with this program at this time or this project has been completely dropped?

I appreciate your efforts

Ali E.


written by seo November 4th, 2008 at 12:37 | #7

Very helpful tips, thank you for sharing!!


written by rich November 7th, 2008 at 20:08 | #8

thank you for everything…
for the creation and the school…
It’s working very fine here.


written by cail November 22nd, 2008 at 14:49 | #9

very nice application
really love it
thanks for the great work!


written by toerist December 29th, 2008 at 08:06 | #10

Thanks for the great info.
my E107 forum limiet is now set higher thanks to using the .htaccess file in the root folder.
works great


written by Eric February 21st, 2009 at 20:08 | #11

Great fix, i’ve had troubles with this for a long time! tnx!


written by mario oyunlar? June 17th, 2009 at 22:58 | #12

thanks for usefull tutorials


written by luis gonzalez August 1st, 2009 at 16:38 | #13

Many many thanks for this awesome application, it’s just what I was looking for the hole week! Thanks for giving the love back!

Muchas gracias y saludos desde México.


written by Padook November 6th, 2009 at 00:13 | #14

Thank you very much, that is exactly what I was looking for… (unfortunately the ini_set did not work)


written by Paul Bennett November 13th, 2009 at 07:44 | #15

Thanks for the .htaccess tip – I didn’t know you could configure php.ini settings there :)

Paul




You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser