What is the maximum file size we can upload using PHP? How to increase it?

By default PHP allows files up to 2 MB. This limit is set by the upload_max_filesize setting. You can increase it in the php.ini file.

upload_max_filesize = 15M
post_max_size = 20M
memory_limit = 128M

You need to change post_max_size also. It is the limit for the whole form data (the file plus other fields), so it must be bigger than upload_max_filesize. If it is smaller, the upload fails without a clear error and $_FILES stays empty.

You can check the current values with ini_get().

<?php
echo ini_get("upload_max_filesize") . "<br>";
echo ini_get("post_max_size");
?>

Output:

Default values

2M
8M

Note: You can not change upload_max_filesize with ini_set() inside the script. Change it in php.ini, in a .user.ini file, or ask your hosting provider. Also check the limit of your web server (for Nginx it is client_max_body_size).

Also read PHP File Upload and the safe upload rules in PHP Security Tips.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.