Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to Change the Maximum Upload file Size in PHP
In PHP, the maximum upload file size is controlled by configuration directives in the php.ini file. By default, PHP sets relatively low limits for file uploads, but you can modify these settings to accommodate larger files.
Key Configuration Directives
Two main directives control file upload limits
- upload_max_filesize Maximum size for individual uploaded files
- post_max_size Maximum size for the entire POST request (should be larger than upload_max_filesize)
Step-by-Step Configuration
Step 1: Locate php.ini File
Find your php.ini file location. For XAMPP users, it's typically located at C:\xampp\php\php.ini. You can also check the location using
<?php echo "php.ini location: " . php_ini_loaded_file(); ?>
Step 2: Edit php.ini File
Open the php.ini file with administrative privileges using a text editor like Notepad. Search for these directives and modify their values
; Set maximum upload file size to 100MB upload_max_filesize = 100M ; Set maximum POST size to 100MB or larger post_max_size = 100M ; Optional: Increase memory limit if needed memory_limit = 256M ; Optional: Increase execution time for large uploads max_execution_time = 300 max_input_time = 300
Step 3: Restart Web Server
After saving the php.ini file, restart your web server (Apache, Nginx, etc.) to apply the changes.
Verify Configuration
You can verify the current upload limits using
<?php
echo "Upload Max Filesize: " . ini_get('upload_max_filesize') . "<br>";
echo "Post Max Size: " . ini_get('post_max_size') . "<br>";
echo "Memory Limit: " . ini_get('memory_limit') . "<br>";
?>
Important Considerations
| Directive | Purpose | Recommended Value |
|---|---|---|
| upload_max_filesize | Individual file limit | Based on your needs (e.g., 50M) |
| post_max_size | Total POST request limit | Same or larger than upload_max_filesize |
| memory_limit | Script memory allocation | 2-3x larger than upload size |
Conclusion
Changing PHP's maximum upload file size requires modifying the upload_max_filesize and post_max_size directives in the php.ini file, followed by a web server restart. Always ensure post_max_size is equal to or larger than upload_max_filesize for proper functionality.
