Important functions of $ _ FILES file upload in php

Source: Internet
Author: User
Tags error code file upload html form php code php tutorial

$ _ Files ["file"] ["name"]-name of the uploaded file
$ _ Files ["file"] ["type"]-type of the file to be uploaded
$ _ Files ["file"] ["size"]-size of the uploaded file, in bytes
$ _ Files ["file"] ["tmp_name"]-name of the temporary copy of the file stored on the server
$ _ Files ["file"] ["error"]-error code caused by file upload

 

<Html>
<Body>

<Form action = "upload_file.php tutorial" method = "post"
Enctype = "multipart/form-data">
<Label for = "file"> filename: </label>
<Input type = "file" name = "file" id = "file"/>
<Br/>
<Input type = "submit" name = "submit" value = "submit"/>
</Form>

</Body>
</Html>

Php code

<? Php

If ($ _ files ["file"] ["type"] = "image/gif ")
| ($ _ Files ["file"] ["type"] = "image/jpeg ")
| ($ _ Files ["file"] ["type"] = "image/pjpeg "))
& ($ _ Files ["file"] ["size"] <20000 ))
  {
If ($ _ files ["file"] ["error"]> 0)
    {
Echo "error:". $ _ files ["file"] ["error"]. "<br/> ";
    }
Else
    {
Echo "upload:". $ _ files ["file"] ["name"]. "<br/> ";
Echo "type:". $ _ files ["file"] ["type"]. "<br/> ";
Echo "size:". ($ _ files ["file"] ["size"]/1024). "kb <br/> ";
Echo "stored in:". $ _ files ["file"] ["tmp_name"];
    }
  }
Else
  {
Echo "invalid file ";
  }

?>

The $ _ files array contains the following content:
$ _ Files ['myfile'] ['name'] original name of the client file.
$ _ 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'] error 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.

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.