Example of form design for uploading multiple files in PHP

Source: Internet
Author: User
This article mainly introduces the form design example for uploading multiple FILES in PHP. This article focuses on how to design the form, and the backend processing needs to be implemented through a loop of $ _ FILES arrays, if you want to upload multiple files, you can see that the process for uploading multiple files is the same as that for uploading individual files. you only need to provide several input forms of the type "file" 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:


<? Php
// 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.

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.