First of all, let me introduce to you the multiple attribute of file in html5
Definition and Usage
The multiple attribute specifies that the input field can select multiple values. If this attribute is used, the field can accept multiple values.
Example:
1 2 3 4 | <form action= "demo_form.asp" method= "get" >
Select images: <input type= "file" name= "img" multiple= "multiple" />
<input type= "submit" />
</form>
|
Copy after login
The input file in the above example can accept multiple file upload fields.
Understanding the multiple attribute of file in html5, let’s start to explain how to use html5 to upload multiple files.
Example code:
html:
1 2 3 4 5 6 7 8 9 10 11 12 | <!DOCTYPE html>
<html>
<head>
<meta charset= "UTF-8" >
</head>
<body>
<form action= "my_parser.php" method= "post" enctype= "multipart/form-data" >
<p><input name= "upload[]" type= "file" multiple= "multiple" /></p>
<input type= "submit" value= "Upload all files" >
</form>
</body>
</html>
|
Copy after login
php code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | for ( $i =0; $i < count ( $_FILES [ 'upload' ][ 'name' ]); $i ++) {
$tmpFilePath = $_FILES [ 'upload' ][ 'tmp_name' ][ $i ];
if ( $tmpFilePath != "" ){
$newFilePath = "./uploadFiles/" . $_FILES [ 'upload' ][ 'name' ][ $i ];
if (move_uploaded_file( $tmpFilePath , $newFilePath )) {
}
}
}
|
Copy after login
Thanks for reading, I hope it can help everyone, thank you for your support of this site!