Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Increase Upload File Size Limit in PHP  (Read 35698 times)

0 Members and 1 Guest are viewing this topic.

nidhinjo

  • Guest
Increase Upload File Size Limit in PHP
« on: April 10, 2018, 12:44:10 am »
The default file size upload limit in php is limited to 2MB. When uploading files to your VPS or dedicated server via a web based content management system or document management system, you may want to increase this file size limit to accomodate larger files.

Modify Three Settings

Set the following three 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.

Two Methods to Change the Settings

Depending on your level of access to the server, you can modify the settings above in two different methods.

Method #1: Edit php.ini


If you are running a (vps) virtual private server or dedicated server, your root account will have access to the php.ini file. This can be edited using the Webmin installation on your server or via SSH

a) Edit php.ini via Webmin
=======================================================================
1.) Open the Webmin control Panel
2.) In the navigation, go to "Others > PHP Configuration"
3.) Click "Manage" next the Global PHP configuration file( URL: https://snag.gy/rH9RKD.jpg )
4.) Click "Resource Limits"
5.) Modify the settings based on the three settings above.
=============================================================================

b) Edit php.ini via SSH

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

Code: [Select]
# vi /etc/php.ini
memory_limit = 128M
upload_max_filesize = 20M
post_max_size = 30M


Save and close the file. Restart Apache web server:
Code: [Select]
# service httpd restart
Method #2: Edit .htaccess


Edit .htaccess file in the root directory of your website. This is useful when you do not have access to the php.ini on a server. You can create the .htaccess file locally and upload it via FTP.

Append / Modify settings:

php_value upload_max_filesize 20M
php_value post_max_size 30M
php_value memory_limit 128M


============================================== :)========================================