PHP upload file Reference configuration large file upload _php instance

Source: Internet
Author: User
Tags php file upload
PHP uses the Super global variable array $_files to record file upload related information, before the php file upload, you can adjust the php.ini in the relevant configuration instructions, to control the upload related details.

1.file_uploads=on/off

Whether to allow uploading of files via HTTP

2.max_execution_time=30

Allow the maximum execution time of the script, which will be an error over this time

3.memory_limit=50m

Set the maximum amount of memory that a script can allocate to prevent runaway scripting from consuming too much RAM, which is set only at compile time
The--ENABLE-MEMORY-LIMIT flag is in effect.

4.upload_max_filesize=20m

Maximum size allowed for uploaded files, this instruction must be less than post_max_size

5.upload_tmp_dir

Upload Files Temporary storage directory

6.post_max_size=30m

Allow post mode to accept maximum size

The contents of the $_files array are as follows: Www.php.net

$_files[' myFile ' [' Name '] The original name of the client's last file.

The MIME type of the $_files[' myFile ' [' type '] file requires the browser to provide support for that information, such as "Image/gif".

$_files[' myFile ' [' size '] the size of the uploaded file, in bytes.

$_files[' myFile ' [' tmp_name '] files are uploaded after the temporary file name stored on the server, usually the system default. Can be specified in the php.ini upload_tmp_dir, but the putenv () function setting is not working.

$_files[' myFile ' [' Error '] and the file upload related status code. [' ERROR '] was added in version PHP 4.2.0. Here is a description of it: (they become constants after PHP3.0)

Upload_err_ok

Value: 0; No error occurred and the file upload was successful.

Upload_err_ini_size

Value: 1; The uploaded file exceeds the value of the Upload_max_filesize option limit 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 files were uploaded.

Value: 5; The upload file size is 0.
After the file is uploaded, it is stored in the temp directory by default, and you must remove it from the temporary directory or move it to another location, or delete it if it is not.

That is, regardless of whether or not the upload succeeds, the files in the temp directory will be deleted after the script executes.

Attachment: How to modify PHP upload file size limit

1. general file upload, unless the file is small. Like a 5M file, it's likely to take more than a minute to upload.

In PHP, however, the default maximum execution time for this page is 30 seconds. That means more than 30 seconds, the script stops executing.

This results in a situation where the Web page cannot be opened. Then we can modify the Max_execution_time

Look in the php.ini.

Max_execution_time

The default is 30 seconds. Change to

Max_execution_time = 0

0 means no Limit

2. Modify Post_max_size to set the maximum allowable size for post data. This setting also affects file uploads.

PHP default post_max_size is 2M. If the POST data size is larger than post_max_size $_post and $_files superglobals will be empty.
Find Post_max_size. instead

Post_max_size = 150M

3. A lot of people will change the second step. However, the maximum upload file is still 8M.

Why, we're going to change one. The parameter upload_max_filesize indicates the maximum size of the uploaded file.

Find Upload_max_filesize, default to 8M instead

Upload_max_filesize = 100M

It is also stated that the 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.