Home >Backend Development >PHP Tutorial >Why Can't I Override `upload_max_filesize` with `ini_set()` in PHP?

Why Can't I Override `upload_max_filesize` with `ini_set()` in PHP?

Barbara Streisand
Barbara StreisandOriginal
2024-12-03 02:26:10300browse

Why Can't I Override `upload_max_filesize` with `ini_set()` in PHP?

PHP: Overriding 'upload_max_filesize' Configuration

You are experiencing issues with setting 'upload_max_filesize' in PHP 5.3.0 using 'ini_set()'. This is likely due to a misunderstanding of PHP configuration settings and their scope.

Shorthand Notation Limitations

Outside of the 'php.ini' file, you cannot use the shorthand notation ('10M') to specify configuration values. This notation is only valid within 'php.ini'. In your case, 'ini_set('upload_max_filesize', '10M')' is interpreting '10M' as '10' in megabytes, resulting in the default 2MB limitation.

'upload_max_filesize' Setting

Additionally, 'upload_max_filesize' is marked as 'PHP_INI_PERDIR' in the PHP configuration settings list. This means that it cannot be overridden using 'ini_set()'. You must set it directly in the 'php.ini' file or modify the .htaccess file to override it for the specific directory.

Restarting Apache Server

After modifying the 'php.ini' file, you need to restart the Apache server for the changes to take effect. This is necessary because the PHP configuration settings are compiled into the Apache configuration on server startup.

Conclusion

To correctly modify 'upload_max_filesize', follow these steps:

  1. Set the value in the 'php.ini' file or .htaccess file.
  2. Restart the Apache server.
  3. Use 'ini_get()' to verify the new value.

The above is the detailed content of Why Can't I Override `upload_max_filesize` with `ini_set()` in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn