The content of the $ _ FILES array is as follows. Assume that the name of the file upload field is file (the name can be arbitrarily named)
$ _ FILES ['file'] ['name'] the original name of the client machine file.
$ _ FILES ['file'] ['type'] indicates the MIME type of the file, which must be supported by the browser, for example, "image/GIF ".
$ _ FILES ['file'] ['SIZE'] size of the uploaded file, in bytes.
$ _ FILES ['file'] ['tmp _ name'] temporary file name stored on the server after the file is uploaded.
$ _ FILES ['file'] ['error'] errors related to the File UploadCode
Value: 0. If no error occurs, the file is uploaded successfully.
Value: 1; the uploaded file exceeds the limit of the upload_max_filesize option in PHP. ini.
Value: 2; the size of the uploaded file exceeds the value specified by the max_file_size option in the HTML form.
Value: 3; only part of the file is uploaded.
Value: 4; no file is uploaded.
PHP's default upload limit is 2 MB. to upload files that exceed this setting, you need to adjust some parameters such as PHP and Apache. next, we will briefly introduce some parameters involved in PHP file upload:
File_uploads
Whether to allow file upload over HTTP. On is enabled by default.
Upload_tmp_dir
Upload_tmp_dir indicates the temporary directory where PHP files are uploaded. to upload files, make sure the server does not have the permission to close the temporary files and write the files to the folder. If not specified, PHP uses the system default value.
Upload_max_filesize
Maximum file size that can be uploaded. The default value is 2 MB.
Post_max_size
Controls the maximum data size that PHP can receive in a form submission using the POST method. If you want to use the PHP file upload function, you need to change this value to a value greater than upload_max_filesize.
Max_input_time
The time for receiving data through post, get, and put is limited in seconds. If the application Program When the running environment is on the low-speed link, you need to add this value to adapt to the more time required to receive data.
Memory_limit
To avoid using a large amount of available memory by running scripts, PHP allows you to define the memory usage limit. Use the memory_limit variable to specify the maximum memory capacity variable memory_limit that can be used by a single script program. The value of memory_limit should be greater than the value of post_max_size.
Max_execution_time
Max_execution_time sets the time for PHP to wait for the script to be executed before the script is forcibly terminated. The time is calculated in seconds. This variable is useful when the script enters an infinite loop state. However, when there is a legal activity that takes a long time to complete (such as uploading large files), this function will also cause operation failure. In this case, you must consider increasing the value of this variable to prevent PHP from closing the script when the script is executing an important process.
For Linux Hosts, the php. conf file may exist under/etc/httpd/CONF. d/access. CONF/. This file may solve the file size restrictions of some systems.
Settings required when uploading large files in PHP
Open PHP. ini, first find
;;;;;;;;;;;;;;;;
; File Uploads;
;;;;;;;;;;;;;;;;
Region, which has the following parameters that affect file upload:
File_uploads = on; whether to allow file upload over HTTP. On is enabled by default.
Upload_tmp_dir; upload the file to the place where the temporary file is stored on the server. If it is not specified, the default Temporary Folder will be used.
Upload_max_filesize = 8 m; wangwen business, that is, the maximum file size allowed to be uploaded. The default value is 2 MB.
In
;;;;;;;;;;;;;;;;;
; Data handling;
;;;;;;;;;;;;;;;;;
Region:
Post_max_size = 8 m; the maximum value that can be received by posting a form to PhP, including all values in the form. The default value is 8 Mb.
Generally, after the preceding four parameters are set, uploading the file <= 8 m is not a problem, but the network is normal.
However, if you want to upload a large file larger than 8 Mb, you can only set the above four items. Unless your network has a high upload speed of 100 Mbit/s, you have to pay attention to the following parameters:
;;;;;;;;;;;;;;;;;;;
; Resource limits;
;;;;;;;;;;;;;;;;;;;
Max_execution_time = 600; maximum time (in seconds) for running each PHP page. The default value is 30 seconds.
Max_input_time = 600; maximum time required for receiving data on each PHP page. The default value is 60 seconds.
Memory_limit = 8 m; maximum memory consumed by each PHP page. The default value is 8 m.
Reproduced from: http://tieba.baidu.com/F? Kz= 662017464