When using PHP to develop a website, sometimes you need to upload large files, but PHP's default upload size limit is 2MB, which obviously cannot meet the demand. Therefore, how to change the PHP upload size limit has become a topic worth discussing.
1. Modify the php.ini file
Open the php.ini file, search for the two parameters post_max_size and upload_max_filesize, replace the original ones with the new limit values and save them . This will expand the upload file size limit.
But it should be noted that modifying the php.ini file requires administrator rights. In addition, for some virtual hosts, the configuration file may not be modified.
2. Use the .htaccess file
Create the .htaccess file in the root directory of the website and add the following content to it:
php_value upload_max_filesize 100M php_value post_max_size 100M
This will The upload file size limit has been expanded to 100MB.
3. Use the ini_set function
In the file upload processing script, use the ini_set function to dynamically set the PHP configuration items. For example:
ini_set('upload_max_filesize', '100M'); ini_set('post_max_size', '100M');
This will temporarily expand the upload file size limit.
However, it should be noted that the configuration options in the php.ini file cannot be modified using the ini_set function, and only temporary dynamic settings can be achieved.
Summary
There are many ways to expand the PHP upload size limit, and the specific choice depends on the actual situation. If you have administrator rights, modifying the php.ini file is the simplest and most effective method; if you cannot operate the php.ini file, you can consider using the .htaccess file or the ini_set function. However, when setting the upload file size limit, it needs to be set reasonably according to the actual situation to avoid excessive burden on the server.
The above is the detailed content of How to change php upload size limit. For more information, please follow other related articles on the PHP Chinese website!