Php uses html5 to upload multiple files to an instance,

Source: Internet
Author: User

Php uses html5 to upload multiple files to an instance,

First, we will introduce the multiple attribute of file in html5.

Definition and usage

The multiple Attribute specifies that multiple values can be selected for the input field. If this attribute is used, the field can accept multiple values.

Instance:

<form action="demo_form.asp" method="get"> Select images: <input type="file" name="img" multiple="multiple" /> <input type="submit" /></form>

The input file in the above instance can accept multiple file upload fields.

After learning about the multiple attribute of file in html5, we will introduce how to use html5 to upload multiple files.

Instance code:

Html:

<!DOCTYPE html>

Php code:

for($i=0; $i<count($_FILES['upload']['name']); $i++) { //Get the temp file path $tmpFilePath = $_FILES['upload']['tmp_name'][$i]; //Make sure we have a filepath if ($tmpFilePath != ""){  //Setup our new file path  $newFilePath = "./uploadFiles/" . $_FILES['upload']['name'][$i];  //Upload the file into the temp dir  if(move_uploaded_file($tmpFilePath, $newFilePath)) {   //Handle other code here  } }}

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

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.