【Foreword】
This article describes the principle of multi-file upload, on the premise of understanding single-file upload
【main body】
(1) You can use $_FILES to accept file information, print and view the array
<form action="" method="post" enctype="multipart/form-data"> <input type="file" name="file[]"/><hr> <input type="file" name="file[]"/><hr> <input type="submit" name="submit" value="提交" /> </form> <?php echo "<pre>"; var_dump($_FILES['file']); echo "</pre>"; ?>
(2) When there are multiple files, it can be seen from the print data that the file information is stored in the array. At this time, a loop is needed to read the information of a single file.
$array = $_FILES['file']['name']; $length = count($array); for($i=0;$i<$length;$i++){ echo "The file name is ".$array[$i]."<br>"; echo "原先保存位置: " . $_FILES["file"]["tmp_name"][$i]."<br>"; move_uploaded_file($_FILES["file"]["tmp_name"][$i],"./upload/" . $array[$i]); echo "Save location after submission: " . "./upload/" . $array[$i]."<br>"; }
Note: Add [$i] after the temporary file name to distinguish
【Key points】
Mainly understand the loop to read a single information, the above is just a simple example, the focus is on logic
.