Home  >  Article  >  Backend Development  >  How to modify the file uploaded by php that is too large

How to modify the file uploaded by php that is too large

PHPz
PHPzOriginal
2023-04-04 09:12:05882browse

During the process of file upload, sometimes the uploaded file is too large. The default file upload size of PHP is 2M, and it cannot upload files that are too large. So how should we deal with it?

The following are some methods to modify the php.ini file:

Method 1: Modify the php.ini file

  1. Open the php.ini configuration file. This file is in the PHP installation directory. The path is similar to /usr/local/php/etc/php.ini
  2. Find the two parameters upload_max_filesize and post_max_size, which are set to the maximum value of the uploaded file and the Web page form respectively. The maximum value of submitted data.
upload_max_filesize=100M
post_max_size=100M

3. Save and close the php.ini file.

  1. Start the php service and re-upload the file.

Method 2: Modify through .htaccess file

1. Open the root directory of your website and find the .htaccess file.

2. Open the file with a text editor and add the following lines:

php_value upload_max_filesize 100M
php_value post_max_size 100M

3. Save and close the .htaccess file.

  1. Start the php service and re-upload the file.

After the above operations, you can successfully upload overly large files. Of course, if you do not want to change the maximum upload file size by modifying the php.ini file, you can also set the upload file size by adding the following content in the PHP script:

ini_set('post_max_size', '100M')
ini_set('upload_max_filesize', '100M')

Use the ini_set() function in PHP to configure upload_max_filesize way, if you want to temporarily change the maximum upload size, others won't be able to see the change and need to be specified in the script.

Summary: File upload is a frequently used function in Web development, and the default upload file size of PHP is 2M. We need to modify the php.ini file or add PHP script configuration to complete the function of uploading large files.

The above is the detailed content of How to modify the file uploaded by php that is too large. 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