For PHP file uploads, refer to configuration of large file uploads _ php instance

Source: Internet
Author: User
Tags php file upload
This article will introduce you to the php File Upload reference configuration big file upload related knowledge, involving php File Upload configuration related knowledge, if you are interested in this, learn about it. PHP uses the super global variable array $ _ FILES to record file upload information. before uploading a php file, you can adjust PHP. configuration commands in ini to control upload details.

1. file_uploads = on/off

Whether to allow file upload through http

2. max_execution_time = 30

The maximum execution time allowed for the script. If this time is exceeded, an error is returned.

3. memory_limit = 50 M

Set the maximum memory size that can be allocated by the script to prevent the out-of-control script from occupying too much memory. This command is only set during compilation.
-- Enable-memory-limit flag

4. upload_max_filesize = 20 M

Maximum size of the file to be uploaded. This command must be smaller than post_max_size.

5. upload_tmp_dir

Temporary directory for storing uploaded files

6. post_max_size = 30 M

Maximum size allowed for post

The $ _ FILES array contains the following content: www.php.net

$ _ FILES ['myfile'] ['name'] original name of the last file on the client.

$ _ FILES ['myfile'] ['type'] indicates the MIME type of the file, which must be supported by the browser, for example, "image/gif ".

$ _ FILES ['myfile'] ['SIZE'] size of the uploaded file, in bytes.

$ _ FILES ['myfile'] ['tmp _ name'] temporary file name stored on the server after the file is uploaded, which is generally the default file name. It can be specified in upload_tmp_dir of php. ini, but the putenv () function setting does not work.

$ _ FILES ['myfile'] ['error'] Status Code related to the file upload. ['Error'] is added in PHP 4.2.0. The following is its description: (they become constants after PHP3.0)

UPLOAD_ERR_ OK

Value: 0. If no error occurs, the file is uploaded successfully.

UPLOAD_ERR_INI_SIZE

Value: 1; the uploaded file exceeds the limit of the upload_max_filesize option in php. ini.

UPLOAD_ERR_FORM_SIZE

Value: 2; the size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form.

UPLOAD_ERR_PARTIAL

Value: 3; only part of the file is uploaded.

UPLOAD_ERR_NO_FILE

Value: 4; no file is uploaded.

Value: 5; the size of the uploaded file is 0.
After the file is uploaded, it is stored in the temporary directory by default. You must delete it from the temporary directory or move it to another place. If it does not exist, it will be deleted.

That is, no matter whether the upload is successful or not, the files in the temporary directory will be deleted after the script is executed.

Appendix: how to modify the size limit of PHP files to be uploaded

1. General file upload, unless the file is very small. It is like a 5 MB file, it may take more than one minute to complete the upload.

However, in php, the longest execution time of the page is 30 seconds by default. That is to say, the script is stopped after 30 seconds.

This causes the web page to fail to be opened. In this case, we can modify max_execution_time.

Search in php. ini

Max_execution_time

The default value is 30 seconds.

Max_execution_time = 0

0 indicates no limit

2. Modify post_max_size to set the maximum size allowed by POST data. This setting also affects file upload.

The default post_max_size of php is 2 MB. If the size of POST data is larger than that of post_max_size $ _ POST and $ _ FILES superglobals, It is null.
Change to post_max_size.

Post_max_size = 150 M

3. Many people will change the second step. But the maximum size of the file to be uploaded is 8 Mb.

Why? We need to change the parameter upload_max_filesize to indicate the maximum size of the uploaded file.

Find upload_max_filesize. The default value is 8 Mb.

Upload_max_filesize = 100 M

In addition, post_max_size is better than upload_max_filesize.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.