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!