PHP File upload code to support multiple file uploads

Source: Internet
Author: User
Tags file size file upload html form php file upload php tutorial

PHP supports uploading multiple files at the same time and automatically organizing their information in the form of an array. To do this, you need to use the same array submission syntax for the file upload fields in the HTML form as the multiple marquee and checkbox.

<title> multiple file uploads </title>
<link rel= "stylesheet" type= "text/css Tutorial" href= "My.css" >
<body>
<form action= "upload_array.php tutorial" method= "POST name=" Upload_multifiles "enctype=" Multipart/form-data ">
Please select File: <br>
<input type= "FILE" name= "userfile[" "size=" > <br>
<input type= "FILE" name= "userfile[" "size=" > <br>
<input type= "FILE" name= "userfile[" "size=" > <br>
<input type= "FILE" name= "userfile[" "size=" > <br>
<input type= "FILE" name= "userfile[" "size=" > <br>
<input type= "Submit" name= "Submit" value= "Start uploading" >

</FORM>

When the above form is submitted, the array $_files[' userfile '],$_files[' userfile ' [' name '] and $_files[' userfile '] [' size '] will be initialized (the previous version of the PHP 4.1.0 is $ Http_post_files). If Register_globals is set to ON, the global variables associated with the file upload will also be initialized. All of these submitted information will be stored in an array indexed by numbers.

For example, if a file named/home/test/review.html and/home/test/xwp.out is committed, the value of the $_files[' userfile ' [' name '][0] will be review.html, and $_files [' UserFile '] [' Name '] The value of [1] will be xwp.out. Similarly, $_files[' userfile ' [' Size '][0] will contain the size of the file review.html, and so on.

In addition, $_files[' UserFile ' [' Name '][0],$_files[' userfile '] [' tmp_name '][0],$_files[' userfile '] [' size '][0] and $_ files[' userfile ' [' type '][0].

PHP files

upload_array.php
--------------------------------
<?php
    for ($i = 0; $i <count ($userfile); $i + +)
    {
        if ($userfile _ name[$i] <> "")//To determine whether the uploaded file is empty
        {
         copy ($userfile [$i], $userfile _name[$i]);

        echo   "filename:  ", $userfile _name[$i], "<br> ";
        echo   "File size:  ", $userfile _size[$i], "<br > ";
        echo   "file type:  ", $userfile _type[$i];
       }
   }
?

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.