Understanding PHP Upload Max Filesize

Home » Documentation » Understanding PHP Upload Max Filesize

The upload_max_filesize directive in PHP determines the maximum size of an uploaded file. This setting helps you control the size of files users can upload to your server. By default, this value is set to 2MB, but you can change it to suit your needs.

How to Change php_upload_max_filesize

To change the upload_max_filesize value, follow these steps:

  1. Locate the php.ini File: This file is usually found in the PHP installation directory.
  2. Edit the php.ini File: Open the file in a text editor and search for php_upload_max_filesize.
  3. Update the Value: Set the desired maximum file size. For example, upload_max_filesize = 10M will set the limit to 10MB.
  4. Restart the Web Server: After making changes, restart the web server to apply the new settings.

Besides php_upload_max_filesize, you should consider other related directives for optimal configuration:

  • php_post_max_size: This directive sets the maximum size of POST data that PHP will accept. It should be larger than upload_max_filesize.
  • php_memory_limit: Ensure this value is larger than post_max_size to handle the uploaded data efficiently.
// Example settings
php_post_max_size = 12M
php_memory_limit = 128M

Interaction with WordPress Settings

WordPress has its memory settings, which can impact file uploads:

  • WP_MEMORY_LIMIT: This defines the default memory limit for WordPress. You can set it in the wp-config.php file.
  • WP_MAX_MEMORY_LIMIT: This setting is used for increasing memory for administrative tasks.

PHP Max Execution Time

The php_max_execution_time directive determines how long a script is allowed to run. If you are uploading large files, you may need to increase this value. This ensures the upload process doesn’t time out.

Configuring upload_max_filesize and related directives ensures smooth file uploads. Remember to align PHP settings with WordPress configurations to avoid issues. By understanding and adjusting these parameters, you can manage file uploads more effectively.