Uploading Large Files to a LAMP setup - upload_max_filesize, post_max_size, and max_allowed_packet
December 28, 2007 on 11:57 am | In linux |So you’re trying to upload a large file via PHP and you’re getting an error, eh? It’s probably because of PHP’s default configuration, which limits uploads to 2 Megs, or because of MySQL’s default 1.5 Meg limitation. Here’s how you change these defaults.
First, find your php.ini file. If you don’t know where it is, create a php file on your server that contains only the following:
<? phpinfo(); ?>
Load that up in your browser and look for the line that says
Configuration File (php.ini) Path
It’s probably set to something like /usr/local/lib/php.ini.
Once found, open up this file and edit the following lines as you see fit:
file_uploads = On
upload_max_filesize = 30M
post_max_size = 30M
In the above example, I’ve updated my configuration to allow uploads of up to 30 Megs.
Once this is complete, restart apache (using something like “/etc/init.d/httpd restart”) and voila, the file upload size limitation should be lifted.
If you’re trying to insert this large uploaded file into a MySQL database, you may, at this time, run into a second limitation:
An error has occured uploading that fileGot a packet bigger than ‘max_allowed_packet’ bytes
SQL: INSERT INTO …
That’s because mysql also has a limit on how large a single SQL query can be. This, too, can be raised - I edited my mysql configuration file at /etc/my.cnf and changed the max_allowed_packet size to 30M as well:
max_allowed_packet = 30M
After doing so, simply restart mysql using something like “/etc/init.d/mysql restart” and the problem should disappear.
Like this story? Share with others on:
 
del.icio.us
digg
reddit
furl
No Comments yet
Sorry, the comment form is closed at this time.
Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds.
Valid XHTML and CSS. ^Top^
44 queries. 0.188 seconds.
