How to Increase Upload Size in PHP: Simple Steps
To increase upload size in PHP, edit the
php.ini file and set higher values for upload_max_filesize and post_max_size. Then restart your web server to apply the changes.Syntax
In the php.ini configuration file, you adjust these two main settings:
upload_max_filesize: Maximum size of an uploaded file.post_max_size: Maximum size of POST data allowed, which must be larger thanupload_max_filesize.
Both values are set with a number followed by a size unit like M for megabytes.
ini
upload_max_filesize = 20M post_max_size = 25M
Example
This example shows how to increase the upload size to 20 megabytes by editing php.ini. After changing, restart your web server to apply.
ini
; php.ini snippet upload_max_filesize = 20M post_max_size = 25M ; Then restart your web server, for example: sudo systemctl restart apache2 ; or sudo systemctl restart nginx
Common Pitfalls
Common mistakes include:
- Setting
upload_max_filesizelarger thanpost_max_size, which causes uploads to fail. - Not restarting the web server after changes, so new limits don't apply.
- Overlooking other limits like
max_execution_timeormemory_limitthat can affect large uploads.
ini
; Wrong configuration example upload_max_filesize = 30M post_max_size = 20M ; Correct configuration example upload_max_filesize = 20M post_max_size = 30M
Quick Reference
Summary tips to increase upload size in PHP:
- Edit
php.inito increaseupload_max_filesizeandpost_max_size. - Make sure
post_max_sizeis larger thanupload_max_filesize. - Restart your web server after changes.
- Check other limits like
max_execution_timeandmemory_limitif uploads still fail.
Key Takeaways
Increase upload size by setting higher values for upload_max_filesize and post_max_size in php.ini.
Always ensure post_max_size is larger than upload_max_filesize to avoid upload errors.
Restart your web server after changing php.ini to apply new settings.
Check related limits like max_execution_time and memory_limit for large file uploads.
Use size units like M (megabytes) when setting upload limits in php.ini.