Php Simple File Image batch upload program code _ PHP Tutorial

Source: Internet
Author: User
Php Simple File Image batch upload program code. The batch upload method is also simple. you only need to add a namepictures [] array to the form, and then use foreach ($ _ FILES [pictures] [error] as $ key $ error) it is also easy to determine the batch upload method for arrays cyclically. we only need to add a name = \ "pictures [] \" array to form, then use foreach ($ _ FILES [\ "pictures \"] [\ "error \"] as $ key => $ error) to cyclically judge the array, and then use move_uploaded_file ($ tmp_name, $ uploadfile); implements file upload.

Html code

The code is as follows:

Upload picture more once

Php processing code

The code is as follows:

If ($ _ POST ['upload'] = 'send '){

$ Dest_folder = "picture /";

If (! File_exists ($ dest_folder )){

Mkdir ($ dest_folder );

}

Foreach ($ _ FILES ["pictures"] ["error"] as $ key => $ error ){

If ($ error = UPLOAD_ERR_ OK ){

$ Tmp_name = $ _ FILES ["pictures"] ["tmp_name"] [$ key];

$ Name = $ _ FILES ["pictures"] ["name"] [$ key];

$ Uploadfile = $ dest_folder. $ name;

Move_uploaded_file ($ tmp_name, $ uploadfile );

}

}

}

?>

The method is quite simple. we just changed the single file upload to multi-file upload, the others are changed to only two places. one is to change the form name to the php array form. The other is to use foreach to upload files to traverse the array.

Explain "pictures [] \" array, and then use foreach ($ _ FILES [\ "pictures \"] [\ "error \"] as $ key => $ error) array loop judgment...

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.