PHP File Upload Processing

Source: Internet
Author: User

The client browser uploads the file, which is implemented by the form file control in HTML, and if the type of the input box is set to file, the pop-up window selects the local file for uploading when clicked.

It is important to note that if a file is uploaded in the form, the form should be sent whether the encoding is set to not encode enctype= "Multipart/form-data".


When the user clicks on the form submission, the file is sent to the receiving server-side script, such as PHP. In PHP, you can use the predefined variable $_files to receive the sent file.


The information received is as follows:

$_files[' myfile ' [' name '] refers to the name of the file being uploaded

$_files[' myfile ' [' type '] refers to the type of file being uploaded

$_files[' myfile ' [' size '] refers to the size of the uploaded file, in bytes (B)


$_files[' myfile ' [' tmp_name '] means the file name of the temporary copy of the file being uploaded to the server, and the file is moved to the specified directory and the pro file is automatically destroyed.


$_files[' myfile ' ["error"] refers to the status code of errors that may appear in the file upload, as explained in the following context.



Error status Code:

0: No error occurred, file upload succeeded.

1: The uploaded file exceeds the value of upload_max_filesize option limit in php.ini

2: The size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form

3: The file is only partially uploaded.

4: No files are uploaded

6: The Temp folder cannot be found. PHP 4.3.10 and PHP 5.0.3 introduced.

7: File write failed. PHP 5.1.0 introduced.



When $_files[' myfile ' [ERROR] returns to 0 to indicate that the file has been uploaded successfully, we need to use the PHP move_uploaded_file () function to move the uploaded temporary file to a new location so that the file is saved to the server.


This article is from the "Grow from Blog" blog, be sure to keep this source http://lxqybyq.blog.51cto.com/7868338/1839469

PHP File Upload Processing

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.