Php Multiple File Upload Image Upload instance-PHP source code

Source: Internet
Author: User
Uploading multiple files is based on uploading a single file and traversing the form array by means of traversing the array, and then uploading the files one by one to the server, next, let's take a look at a simple multi-File Upload instance. Multiple files are uploaded by traversing the array based on a single file and then uploading the files to the server one by one, next let's take a look at a simple multi-File Upload instance.

Script ec (2); script

The process for uploading multiple files is the same as that for uploading individual files. You only need to provide multiple input forms of the "file" type on the client and specify different "name" attribute values. For example, in the following code, you can upload three local files to the server at the same time. The form of the client is as follows:

The Code is as follows:


Multiple File Upload forms



In the above Code, three file types of forms are organized in the form of arrays. When the above form teaches PHP the script file mul_upload.php, the server also uses a Global Array $ _ FILES to store all the information of the above FILES, however, $ _ FILES has been changed from a two-dimensional array to a three-dimensional array, so that the information of multiple uploaded FILES can be stored. In the script file mul_upload.php, use the print_r () function to output the content in the $ _ FILES array. The Code is as follows:

The Code is as follows:
// Print the content in the 3D array $ _ FILES and check the structure of the uploaded file.
Print_r ($ _ FILES );
?>

After three local files are selected for submission, the output result is as follows:

The Code is as follows:

Array (
[Myfile] => Array (
[Name] => Array (--- $ _ FILES ["myfile"] ["name"] stores the content of all uploaded FILES
[0] => Rav. ini --- $ _ FILES ["myfile"] ["name"] [0] name of the first uploaded file
[1] => msgsocm. log --- $ _ FILES ["myfile"] ["name"] [1] name of the second uploaded file
[2] => NOTEPAD. EXE) --- $ _ FILES ["myfile"] ["name"] [2] name of the third uploaded file
[Type] => Array (--- $ _ FILES ["myfile"] ["type"] stores all types of uploaded FILES
[0] => application/octet-stream --- $ _ FILES ["myfile"] ["type"] [0] type of the first file to be uploaded
[1] => application/octet-stream --- $ _ FILES ["myfile"] ["type"] [1] type of the second uploaded file
[2] => application/octet-stream) --- $ _ FILES ["myfile"] ["type"] [2] type of the third object to be uploaded
[Tmp_name] => Array (
[0] => C:/WINDOWS/Temp/phpAF. tmp
[1] => C:/WINDOWS/Temp/phpB0.tmp
[2] => C:/WINDOWS/Temp/phpB1.tmp)
[Error] => Array (
[0] => 0
[1] => 0
[2] => 0)
[Size] => Array (
[0] => 64
[1] => 1350.
[2] = & gt; 66560 ))
)

The output value of the $ _ FILES array shows that the process of uploading multiple FILES is the same as that of uploading a single file, but the structure of the $ _ FILES array is slightly different. In this way, more files can be uploaded.

Example

The Code is as follows:





Document Upload


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.