PHP Bulk Upload file

Source: Internet
Author: User

form.php

 


upload.php

Set the upload file size limit (unit B) $max _size=500000;
Set the file format of the upload file limit $format =array ("Image/jpeg", "Image/gif", "image/png"); File upload directory $dir =dirname (__file__). "

/upload/";

Determine the upload directory, do not exist on the Create if (!is_dir ($dir)) {mkdir ($dir, True);} 
    Bulk upload file for ($i =0, $j =count ($_files["file"] ["name"]) $i < $j; $i + +) {//uploaded file name $name =$_files["file"] ["name"] [$i];
    The type of file being uploaded $type =$_files["file" ["type"] [$i];
    The size of the uploaded file, in bytes $size =$_files["File" ["Size"] [$i];
    The name of the temporary copy of the file stored on the server $tmp _name=$_files["file" ["Tmp_name"] [$i];
    
    The error code caused by the file upload $error =$_files["file" ["Error"] [$i];
    Determine the file size if ($size > $max _size) {exit ("File size exceeds maximum");
    }//Judge file format if (!in_array ($type, $format)) {exit ("Invalid file format");
    ///Generate filename Date_default_timezone_set ("PRC");
    $file _name=time (). Mt_rand (1111, 999999);
    
    Gets the file format $ext =substr ($type, Strpos ($type, "/") +1);
    if ($error >0) {exit ($error); }else{if (Move_uploaded_file ($tmp _name, $dir. $file_name. "." 
        $ext)) {//exit ("uploaded success"); }
    }

}





















Related Article

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.