Example of form design for uploading multiple files in PHP, _php tutorial

Source: Internet
Author: User

Example of a form design that uploads multiple files in PHP,


Multiple file uploads and individual file uploads are handled the same way, with only a few input forms of type "file" in the client, and a different "name" attribute value specified. For example, in the following code, you can have the user select three local files to pass to the server together, and the client's form looks like this:
Copy the Code code as follows:

Multiple file Upload forms




In the preceding code, a form of three file types is organized as an array. When the above form teaches PHP script file mul_upload.php, the server side also uses global array $_files to store all of the above-mentioned files, but $_files is transformed from a two-dimensional array into a three-dimensional array, so that it can store multiple uploaded files of information. In the script file mul_upload.php, use the Print_r () function to output the contents of the $_files array, as shown in the following code:

Copy the Code code as follows:
<?php
Print the contents of a three-dimensional array $_files, and look at the structure of the stored upload file
Print_r ($_files);
?>

When three local file submissions are selected, the output is as follows:
Copy the code code as follows:
Array (
[Myfile]=>array (
[name]=> Array (---$_files["myfile" ["name"] stores the contents of all uploaded files
[0]=>rav.ini---$_files["myfile" ["Name"][0] The name of the first uploaded file
[ 1]=>msgsocm.log---$_files["myfile" ["Name"][1] The name of the second upload file
[2]=>notepad. EXE)---$_files["myfile" ["Name"][2] The name of the third upload file
[Type]=>array (---$_files["myfile"] ["type"] stores all uploaded file types
[ 0]=>application/octet-stream---$_files["myfile" ["type"][0] the first type of upload file
[1]=>application/octet-stream-- -$_files["MyFile" ["type"][1] the second type of upload file
[2]=>application/octet-stream]---$_files["myfile" ["Type"][2] Type of the third upload file
[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]=>66560])
)

By outputting the value of the $_files array, you can see that the upload of multiple files is the same as when uploading a single file, except that the $_files array has a slightly different structure. This way you can support a larger number of file uploads.

http://www.bkjia.com/PHPjc/914041.html www.bkjia.com true http://www.bkjia.com/PHPjc/914041.html techarticle PHP Upload a number of files in the form design example, multiple file uploads and individual file upload processing method is the same, only need to provide several types of "file" input to the client ...

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