php.ini modification upload

王林
Release: 2023-05-06 18:04:07
Original
599 people have browsed it

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.

  1. Create a php file and insert the following code in it:

phpinfo();
?>

  1. Open the browser and access the URL where the php file is located.
  2. In the browser, you will see a page containing various PHP settings. On this page, look for the "Loaded Configuration File" or "php.ini" field to determine the location of the php.ini file.

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:

  1. Modify the size limit of uploaded files

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.

  1. Add more file types

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template