Home >Backend Development >PHP Problem >php.ini modification upload
PHP is a common server-side scripting language, widely used in web development, server-side scripting and other fields. During PHP development, sometimes you need to upload files to the web server. However, by default, PHP may limit the size and type of uploaded files, so you need to modify the php.ini file to adjust the upload settings. This article will explain how to modify the php.ini file to allow larger uploads and more file types.
1. Determine the location of the php.ini file
The php.ini file is the PHP configuration file, which contains various settings of PHP, including upload settings. However, the location of the php.ini file varies between different servers. Some servers may place the php.ini file in the PHP installation directory, while others may place it in a directory on the server system. In this case, the location of the php.ini file can usually be located by using the phpinfo() function in the PHP code.
phpinfo();
?>
2. Modify the upload settings
After finding the php.ini file, you can start modifying the upload settings in it. The following are two settings that may need to be modified:
By default, PHP may limit the size of uploaded files to less than 2M . This is often too small for applications that need to upload large files, so the php.ini file needs to be manually modified to expand the upload file size limit. Find the following setting in the php.ini file:
upload_max_filesize = 2M
Change it to the desired size, for example:
upload_max_filesize = 20M
This will allow uploading files under 20MB.
By default, PHP only allows uploading some common file types, such as jpg, png, gif and other image file types. However, sometimes other file types need to be uploaded (such as PDF files, Word documents, etc.), so the php.ini file needs to be manually modified to add more file types.
Find the following settings in the php.ini file:
;upload_max_filetype = "application/octet-stream"
Remove the semicolon in front and add the required file type, for example:
upload_max_filetype = "application/octet-stream","application/pdf","application/msword"
This will allow uploading octet-stream, PDF and Word Documentation files.
After modifying the php.ini file, you need to restart the web server for the settings to take effect. After the operation is completed, the upload function should be tested again to ensure that the modification was successful.
Summary:
Modifying the php.ini file is a critical step in allowing larger uploads and adding more file types. During this process, you must determine the location of the php.ini file and modify the required upload settings. This setting includes upload file size limits and upload file types. Once you have completed these steps, you should restart the web server and test the upload functionality to ensure the modifications are correct.
The above is the detailed content of php.ini modification upload. For more information, please follow other related articles on the PHP Chinese website!