欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php 多文件上傳的實(shí)現(xiàn)實(shí)例

 更新時(shí)間:2016年10月23日 14:36:28   投稿:lqh  
在php中,實(shí)現(xiàn)文件上傳時(shí)一個(gè)很簡(jiǎn)單的事情,但是如果我們要一次上傳多個(gè)文件,那又該如何編寫代碼呢?,需要的朋友可以參考下

首先向大家講解一下實(shí)現(xiàn)的方法。

要實(shí)現(xiàn)多文件上傳,我們可以在form表單中添加多個(gè)input file域,然后將這些input file的name屬性設(shè)置為相同的名稱且使用數(shù)組的形式命名,例如filename[]。至于文件上傳的php代碼和單個(gè)文件上傳是一樣的道理。

下面看一個(gè)多文件上傳的實(shí)例:

html文件example.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<form action="my_parser.php" method="post" enctype="multipart/form-data">
 <p><input type="file" name="file_array[]"></p>
 <p><input type="file" name="file_array[]"></p>
 <p><input type="file" name="file_array[]"></p>
 <input type="submit" value="Upload all files">
</form>
</body>
</html>

php文件my_parser.php

<?php
if(isset($_FILES['file_array'])){
  $name_array = $_FILES['file_array']['name'];
  $tmp_name_array = $_FILES['file_array']['tmp_name'];
  $type_array = $_FILES['file_array']['type'];
  $size_array = $_FILES['file_array']['size'];
  $error_array = $_FILES['file_array']['error'];
  for($i = 0; $i < count($tmp_name_array); $i++){
    if(move_uploaded_file($tmp_name_array[$i], "test_uploads/".$name_array[$i])){
      echo $name_array[$i]." upload is complete<br>";
    } else {
      echo "move_uploaded_file function failed for ".$name_array[$i]."<br>";
    }
  }
}
?>

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論