Home >Backend Development >PHP Problem >How to modify the size of uploaded files in php
PHP is a programming language widely used in web development. Its file upload function is an important part because it can help you upload files to the web server for access and use. However, by default, PHP upload file size limit is relatively low, if you need to upload larger files, you may need to modify the PHP configuration. This article will introduce how to modify the upload file size in PHP.
1. Understand the size limit of PHP upload files
By default, the default file upload size limit of PHP is 2MB. This ensures that uploaded files are not too large, thus avoiding overloading the server, but if you need to upload files larger than 2MB, you will have to modify your PHP configuration. To know your PHP file upload size limit, you can check the following line in your php.ini file:
upload_max_filesize = 2M
This line tells you the maximum size of the uploaded file, which defaults to 2MB. If you want to modify the limit, you need to modify this value.
2. Modify the PHP upload file size limit
If you need to upload larger files, you can modify the value of upload_max_filesize as follows:
To modify the size of PHP upload files, you need to modify the php.ini file. This file is usually included with the PHP installation, and you can find the settings that need to be modified in the php.ini file. You can find the php.ini file using the following command:
php --ini
Once you find the php.ini file, you can open and edit it using the following command It (assuming you are using the VI Editor):
sudo vi /etc/php/php.ini
Find the following line:
upload_max_filesize = 2M
Change it to the value you want. For example, if you want to increase the upload size limit to 50MB, you can change it to:
upload_max_filesize = 50M
In addition to modifying upload_max_filesize, you also Post_max_size needs to be modified. This setting controls the amount of data that the form's POST method can send. In most cases it should be larger than upload_max_filesize. Find the following line in the php.ini file:
post_max_size = 8M
and change it to your desired value:
post_max_size = 50M
After completing the changes, you need to restart the web server to ensure that the changes take effect. You can use the following command to restart the Apache server:
sudo service apache2 restart
You can also use the following command to restart the nginx server:
sudo service nginx restart
Now that you have completed the process of modifying the PHP upload file size limit, you should be able to upload The file is larger. This is important for web applications that need to upload large media files such as video and audio.
Summary
To modify the PHP upload file size limit, you need to modify the php.ini file, change the values of upload_max_filesize and post_max_size, and then restart the web server. This will enable you to upload larger files, making your web application more flexible and powerful.
The above is the detailed content of How to modify the size of uploaded files in php. For more information, please follow other related articles on the PHP Chinese website!