Php multi-file and image upload example details, _ PHP Tutorial

Source: Internet
Author: User
Multiple php file and image Upload instances are described in detail ,. The following describes how to upload multiple php files and images. Share it with you for your reference. The specific implementation method is as follows: multiple files php multiple files and image Upload instance details,

This example describes how to upload multiple php files and images. Share it with you for your reference. The specific implementation method is as follows:

Uploading multiple files is based on uploading a single file and traversing the form array by means of traversing the array and uploading the files one by one to the server. next we will look at a simple example of uploading multiple files.

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:

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