PHP.INI: File upload function configuration

巴扎黑
Release: 2016-11-29 09:59:58
Original
959 people have browsed it

Note: If it is Apache Server, you should configure the php.ini file in the apache folder
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.

 Instructions for the file upload function configuration options in php.ini

Open the php.ini configuration file and find File Uploads

 file_uploads = On

  HTTP file uploads are allowed by default, and this option cannot be set to OFF.

  upload_tmp_dir =

The default is empty. This option is also easy to forget 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', which means there is a leapsoulcn directory in the C drive directory. It is the same as the session configuration. If you are in a Linux environment, you must give this directory writable permissions.

  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. One mistake that PHP beginners often 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, so 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, you must set this option to a value greater than the value of the upload_max_filesize command. I generally set the upload_max_filesize and post_max_size values ​​to be equal. In addition, if memory limit is enabled, this value should be smaller than the value of the memory_limit option.

  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 in the php.ini configuration file The max_execution_time configuration option is causing trouble, which indicates the maximum allowed execution time (in seconds) of each script, and 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 PHP tutorial for configuring the file upload option in the php.ini configuration file has been introduced. Through the practice and learning of the above steps, combined with the PHP program, the file upload function can be realized.

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!