Home >Backend Development >PHP Tutorial >Detailed explanation of php.ini file upload function configuration

Detailed explanation of php.ini file upload function configuration

WBOY
WBOYOriginal
2016-07-25 08:54:551193browse
I will introduce to you how to configure the php file upload function in the php.ini file, which involves some important options and is related to the size limit of php upload files. Friends in need can refer to it.

Share some key php.ini configurations when using PHP to implement the file upload function.

PHP file upload function configuration mainly involves options such as upload_tmp_dir, upload_max_filesize, post_max_size in the php.ini configuration file.

1. Description of configuration options for the file upload function in php.ini

 Open the php.ini configuration file and find File Uploads file_uploads = On

  HTTP file upload is allowed by default, this option cannot be set to OFF. ​upload_tmp_dir =

 The default is empty. When manually configuring the PHP running environment, if this option is not configured, the file upload function cannot be implemented. This option sets the temporary directory where files are stored when uploading files. You must assign a value to this option, such as upload_tmp_dir. ='/leapsoulcn' means that there is a leapsoulcn directory in the C drive directory. It is the same as the session configuration. If it is in a Linux environment, this directory must be given writable permissions.

Second, how to upload large files exceeding 8M?

Uploading large files mainly involves configuring two options: upload_max_filesize and post_max_size.

 The default file upload size in the php.ini configuration file is 2M. The most common mistake to make is to set the form area for the maximum size of the uploaded file when writing the file upload function, that is, the maximum value of the file allowed to be uploaded, max_file_size (hidden value field) value to specify the size of the uploaded file. In fact, generally others can bypass this value. For safety reasons, it is best to configure the upload_max_filesize option in the php.ini configuration file to set the size of the file upload.

 The default upload_max_filesize = 2M, that is, the file upload size is 2M. If you want to upload a file exceeding 8M, such as 20M, you must set upload_max_filesize = 20M.

 However, just setting upload_max_filesize = 20M still cannot realize the upload function of large files. You must modify the post_max_size option in the php.ini configuration file, which represents the maximum byte length of data allowed for POST, and the default is 8M. If the POST data exceeds the limit, $_POST and $_FILES will be empty.

To upload large files, the value of this option must be set greater than the value of the upload_max_filesize command. Generally, the values ​​of upload_max_filesize and post_max_size are set to be equal. Additionally, if memory limit is enabled, this value should be less than the value of the memory_limit option.

Three, other precautions for file upload

When uploading large files, you will feel that the upload speed is slow. When it exceeds a certain time, an error will be reported that the script execution exceeds 30 seconds. This is because the max_execution_time configuration option in the php.ini configuration file is causing trouble, which means The maximum allowed execution time of each script (in seconds), 0 means no limit. You can adjust the value of max_execution_time appropriately. Setting it to 0 is not recommended.

 At this point, the configuration of file upload options in the php.ini configuration file has been introduced. I hope it will help everyone master the method of uploading php files.



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