PHP File Upload form code

Source: Internet
Author: User
Tags php file upload
Welcome to the Linux community forum and interact with 2 million technical staff to enter the parameter description $ type, $ name, $ size, $ error, $ tmp_name corresponds to the related variables in the global variables $ _ FILES, that is: $ _ FILES [userfile] [type]: MIME type of the file, which must be supported by the browser, for example, imagegif. $ _ FILES

Welcome to the Linux community forum and interact with 2 million technical staff> enter parameter description $ type, $ name, $ size, $ error, $ tmp_name corresponds to the related variables in the global variable $ _ FILES, that is, $ _ FILES ['userfile'] ['type']: The MIME type of the file, this information must be supported by the browser, for example, image/gif ". $ _ FILES

Welcome to the Linux community forum and interact with 2 million technicians>

Parameter description

$ Type, $ name, $ size, $ error, $ tmp_name corresponds to the related variables in the global variable $ _ FILES, that is:

$ _ FILES ['userfile'] ['type']: MIME type of the file, which must be supported by the browser. For example, the file type is "image/gif ".

$ _ FILES ['userfile'] ['name']: the original name of the client file.

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

$ _ FILES ['userfile'] ['tmp _ name']: temporary file name stored on the server after the file is uploaded.

$ _ FILES ['userfile'] ['error']: error Code related to the file upload, that is

Value: 0: 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.

$ Ext: File Upload Extension

$ Targetname: The final file name after the file is uploaded

$ Upload_dir: directory to which the object is uploaded. The relative path is used.

Note:

3rd rows ~ Row 6th: sets the size of the image file to be uploaded, the MIME type and extension of the file. Because this code is an image file upload program, all the image types are listed in the two arrays, for example, PNG, GIF, and JEPG.

17th rows ~ Row 24th: if the file is empty, the size is equal to 0. If the image file extension or type does not match, the file jumps out.

Row 26th: The move_uploaded_file function moves the files in the temporary directory of the server set by upload_tmp_dir to the Files specified by $ file_path. Note that if the target file already exists, it overwrites the target file.

How to upload multiple files? For example, upload three files simultaneously.

You only need

  

Change

  

  

  

When this function is called, $ _ FILES ['userfile'] ['name'] [0] indicates information about the first file, the same applies to others.

Summary

This function is the simplest core code for PHP File Uploading. image uploading is only one of them. You only need to modify or expand the information about the $ FILE_MIMES and $ FILE_EXTS arrays, you can upload other types of files. On the periphery of the function, you can write other relevant code as needed to implement other functions, such as database Association.

[1] [2]

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.