Hostao LLC

How to Increase Maximum Upload Size in PHP and Optimize Your PHP Upload Code

At some point in your PHP development journey, you may encounter a predicament where you need to upload files that surpass the typical upload size. Fear not, as there are several methods to increase PHP’s maximum upload size. This can be a thorny issue to contend with. Still, fortunately, we’ll take you through the process step-by-step in this post, replete with some tactics and pointers for refining your PHP upload code and enhancing your website’s functionality.

Let’s go into the specifics of increasing PHP’s maximum upload size.

Step 1 Check the Current Maximum Upload Size

The first step involves determining the current maximum upload size limit for PHP. You can accomplish this by creating a PHP file with the following code:

Upload the file to your server after saving it as phpinfo.php. Next, open your web browser and go to This will produce a page jam-packed with information on your PHP installation.

Look for the line that reads “upload_max_filesize.” This line specifies the current maximum upload size limit for your PHP installation.

Step 2 Increase the Maximum Upload Size Limit

It’s time to raise the upload size restriction now that you know what it is currently set at. To do this, alter your PHP configuration file. Depending on how your server is configured, this file’s name and location may change, although it is commonly known by the name php.ini.

Search for the following lines in php.ini:

To set the maximum upload size limit, modify the values of upload max filesize and post max size. To increase the limit to 100MB, for instance, you may change the settings as follows:

To apply the modifications, save the php.ini file and restart your web server.

Step 3 Test the Maximum Upload Size

It’s critical to verify that the maximum upload size restriction is operating as intended after increasing it. Put the following code into a PHP file:

Upload the file to your server after saving it as test.php. then open your web browser and navigate to The new maximum upload size restriction you established in Step 2 should be visible.

Code Optimization for PHP Upload

It’s critical to optimize your PHP upload code after raising the maximum upload size limit in PHP to improve your website’s speed. Here are some pointers and strategies to help you achieve that:

Use a file upload library – Instead of developing your file upload code from scratch, consider employing a file upload library like PHP’s built-in $_FILES superglobal or a third-party library like DropzoneJS or Fine Uploader.

Validate file types and sizes – Before permitting users to upload files to your website, verify the file types and sizes to prevent malevolent uploads and guarantee that your server can handle the uploaded files.

Use asynchronous uploads – Consider utilizing asynchronous uploads that enable users to upload files in the background while they continue using your website to enhance your website’s performance.

Compress and optimize uploaded files – To save disk space and improve download times, compress and optimize uploaded files using a library like ImageMagick or GD.


The diagram below illustrates the process of increasing the maximum upload size in PHP:


To sum up, changing the php.ini configuration file makes increasing the maximum upload size in PHP rather simple. It is essential to optimize your PHP upload code in order to ensure that your website functions properly and to prevent fraudulent uploads.

We hope that this post has given you the knowledge and direction you need to boost the PHP upload code optimization and maximum upload size. Please feel free to leave a remark below if you have any queries or suggestions. I appreciate your reading.