PHP File Upload $_files global variable usage Introduction

Source: Internet
Author: User
Tags html form php file upload

Let's take a look at the use of the variables in files

The

$_files Super global variable is special, and is the only two-dimensional array in a predefined super-global array. The role is to store various information about uploading files that are critical to files uploaded to the server via PHP scripts. There are a total of 5 items in this function:
1.$_files["UserFile" ["Error"]
$_files["UserFile" ["error"] Array values provide important information about the results of the upload attempt. There are 5 different return values, one representing a successful result, and another 4 representing the special error that occurred in the attempt. The name of the return value and will be described later.
2.$_files["UserFile" ["Name"]
$_files["UserFile" ["name"] variable specifies the original name of the file declared on the client machine, including the extension. Therefore, if the browser is a file named Vacation.jpg and uploaded through the form, the value of this variable will be vacation.png.
3.$_files["UserFile" ["Size"]
$_files["UserFile" ["Size"] variable specifies the size, in bytes, of the file uploaded from the client. Therefore, in the example of the vacation.jpg file, this function may be assigned a value of 5253, which is approximately 5kb.
4. $_files["UserFile" ["Tmp_name"]
$_files["UserFile" ["Tmp_name"] variable specifies the temporary name given to the file after uploading to the server. This is the file name that is specified when stored in the TEMP directory (specified by PHP Directive upload_tmp_dir).
5. $_files["UserFile" ["type"]
$_files["UserFile" ["type"] variable specifies the MIME type of the file uploaded from the client. Therefore, in the example of the vacation.jpg file, this variable is assigned a value of Image/jpeg. If you are uploading a PDF, the assignment is application/pdf. Because this variable sometimes gets unexpected results, it should be shown in the script to be validated.


$_files[' myFile ' [' Error '] and the file upload related error 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.

PHP File Upload $_files global variable usage Introduction

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.