Change the maximum upload file size

Change the maximum upload file size

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Changing Maximum Upload File Size: The PHP Configuration Hierarchy

When an upload form rejects files exceeding a certain limit, it is rarely because your application logic is hardcoded to reject them. Instead, you are almost certainly hitting one of several server-side constraints that act as a safety net before your script even runs. The most common error encountered in this scenario involves the upload_max_filesize directive, but resolving it requires navigating a specific hierarchy of configuration files.

The standard approach for adjusting these limits involves modifying the PHP configuration. However, simply creating a custom php.ini file in your project root or attempting to edit .htaccess often fails, particularly on shared hosting environments or managed servers where you lack access to the main server configuration. This happens because PHP does not automatically load local php.ini files unless specific conditions are met, and Apache's .htaccess file has limited capability to alter memory-related directives like upload_max_filesize.

To understand why your previous attempts failed, it is necessary to look at how PHP loads its configuration. When a script starts, PHP searches for the active configuration file based on a specific priority order. If you place a php.ini file in the document root of your website, it will only be used if no other configuration file has already been loaded by the time PHP reaches the current directory. On many shared hosting platforms, the administrator pre-loads a global php.ini, and local files are ignored to prevent accidental misconfigurations that could crash the server. Similarly, directives related to memory limits, such as upload_max_filesize and post_max_size, cannot be modified via .htaccess. These require changes at the Apache or PHP core level, which you cannot access without root privileges.

The most reliable method to increase the upload limit is to locate and modify the active PHP configuration file directly. Since you do not have access to the server's main php.ini, you must identify if a local override exists or if you are using a virtual host specific configuration. On systems where .htaccess restrictions prevent direct modification, the solution often lies in finding a php.ini file within your project directory that PHP is actually loading. You can verify this by creating a simple script containing <?php phpinfo(); ?> and searching the output for "Configuration File (php.ini) Path." If that path points to a location outside your project, editing it locally will have no effect.

If you are operating in an environment where you cannot modify the main configuration or find a local override, the alternative is often limited. You may need to contact your hosting provider's support team to request an increase in the upload limit. They can adjust the upload_max_filesize and post_max_size directives in their global pool of configurations. It is crucial to remember that these two settings must be aligned; post_max_size should always be slightly larger than upload_max_filesize. If you increase upload_max_filesize but leave post_max_size at its default (usually 8MB), the server will still reject files larger than 8MB because it cannot process the POST data beyond that threshold.

For applications built with frameworks like Laravel, similar constraints apply regardless of where the code resides. While you might adjust environment variables in .env for application logic, the PHP SAPI layer enforces these hard limits first. If you are using a managed service or a PC-based host without administrative access, the only viable path forward is usually an external configuration change by the system administrator. Attempting to bypass this via local files on such systems is destined to fail because the server simply ignores them in favor of the pre-configured defaults designed for stability and security.

Our network