PHP Increase Upload File Size Limit

Your php installation putting limits on upload file size. The default will restrict you to a max 2 MB upload file size. You need to set the following two configuration options:

  1. upload_max_filesize - The maximum size of an uploaded file.
  2. memory_limit - This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.
  3. post_max_size - 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. If memory limit is enabled by your configure script, memory_limit also affects file uploading. Generally speaking, memory_limit should be larger than post_max_size.
  4. There are two methods two fix this problem.

Method # 1: Edit php.ini

Edit your php.ini file (usually stored in /etc/php.ini or /etc/php.d/cgi/php.ini or /usr/local/etc/php.ini):
# vi /etc/php.ini
Sample outputs:

 
memory_limit = 32M
upload_max_filesize = 10M
post_max_size = 20M
 

Save and close the file. Restart apache or lighttpd web server:
# service httpd restart
OR
# service lighttpd restart

Method #2: Edit .htaccess

Edit .htaccess file in your root directory. This is useful when you do not have access to php.ini file. In this example, /home/httpd/html is considered as root directory (you can also create .htaccess file locally and than upload it using ftp / sftp / scp client):
# vi /home/httpd/html/.htaccess
Append / modify setting as follows:

 
php_value upload_max_filesize 10M
php_value post_max_size 20M
php_value memory_limit 32M
 

Save and close the file.

A Note About Suhosin (Optional)

This is not installed by default on many servers (latest version of Debian, Ubuntu, and FreeBSD does install Suhosin by default). Use phpinfo() to find out if suhosin enabled or not (create test.php):

 

phpinfo();
?>
 

If you are using Suhosin which was designed to protect your servers against a number of well known problems in PHP applications and on the other hand against potential unknown vulnerabilities within these applications or the PHP core itself. You need to edit /etc/php.d/suhosin.ini to set correct memory and upload limit. As long scripts are not running within safe_mode they are free to change the memory_limit to whatever value they want.
suhosin.memory_limit=32M

Was this answer helpful?

 Print this Article

Also Read

How do I find out System / Server Memory Utilization

free command example Type the free command at shell prompt: $ free $ free -m Output:...

How Do I Block an IP Address on My Linux server?

How do I block an IP address or subnet under Linux operating system? In order to block an IP on...

yum update Linux Error: Missing Dependency: xen-libs

When I type "yum update" under RHEL 5.x server I get the following error: Error: Missing...

OpenSSH Hide Version Number From Clients

How do I hide ssh number from clients? When I type the following command it displays server...

CentOS / Redhat: Install nginx As Reverse Proxy Load Balancer

nginx is a Web and Reverse proxy server. Nginx used in front of Apache Web servers. All...