PHP file upload size setting method

WBOY
Release: 2016-07-25 08:54:51
Original
1298 people have browsed it
This article introduces how to set the file upload size in PHP and how to break through the PHP upload limit. Friends in need can refer to it.

In PHP programming, to break through the PHP upload size limit, you can operate as follows.

Open the upload_tmp_dir, upload_max_filesize, post_max_size and other options in the php.ini configuration file.

Explanation of configuration options for file upload function in php.ini

Open the php.ini configuration file and find File Uploads file_uploads = On HTTP file uploads are allowed by default, this option cannot be set to OFF. upload_tmp_dir = The default is empty. This option is 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 give this option Assigning a value, 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 you are in a Linux environment, you must give this directory writable permissions.

How to upload large files exceeding 8M? That is, how to modify php upload restrictions. Uploading large files mainly involves configuring the 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.

But 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. The default is 8M. If the POST data exceeds the limit, $_POST and $_FILES will be empty. To upload large files, you must set the value of this option to be greater than the value of the upload_max_filesize command. Generally, the upload_max_filesize and post_max_size values ​​are set to be equal.

In addition, if memory limit is enabled, the value should be smaller than the value of the memory_limit option.

Other considerations for php 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. It means The maximum allowed execution time of each script (in seconds), 0 means no limit. The value of max_execution_time can be adjusted appropriately. Setting it to 0 is not recommended.



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