In addition to changing your code, you also need to change the setting on the server to accommodate uploading larger file sizes.

The settings that need to be changed are in the php.ini file:

sudo vi /etc/php/7.0/apache2/php.ini

(the path here is for PHP ver 7.0)

The following settings need to be checked:

upload_max_filesize – controls the maximum size of each file
max_file_uploads – sets the maximum number of files that can be uploaded at a time
post_max_size – max size of POST data that PHP will accept. This value should be at least as big as upload_max_filesize * max_file_uploads
memory_limit – max amount of memory a script may consume. This value should be at least as big as post_max_size

Possibly you might want to increase these as well:

max_execution_time – max execution time of each script, in seconds
max_input_time – max amount of time each script may spend parsing request data

For example if you would like to be able to upload 20 files at a time, each of which could be up to 10MB in size:

upload_max_filesize = 10M
max_file_uploads = 20
post_max_size = 208M
memory_limit = 216M

Once the the changes to the php.ini file are made, you need to restart Apache:

sudo service apache2 restart
PHP.ini settings to increase file size and number of uploads
Tagged on:             

Leave a Reply

Your email address will not be published. Required fields are marked *