最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2016年10月24日 08:22:24   投稿:lqh  
在html沒(méi)有出來(lái)之前,要實(shí)現(xiàn)php多文件上傳比較麻煩,需要在form表單里面添加多個(gè)input file域。html5發(fā)布以后,我們可以使用input file的html5屬性multiple來(lái)實(shí)現(xiàn)多文件上傳,需要的朋友可以參考下

首先向大家介紹一下html5中file的multiple屬性

定義和用法

multiple 屬性規(guī)定輸入字段可選擇多個(gè)值。如果使用該屬性,則字段可接受多個(gè)值。

實(shí)例:

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

上面實(shí)例中的input file 可接受多個(gè)文件上傳字段。

了解了html5中file的multiple屬性,下面我們開(kāi)始講解使用html5實(shí)現(xiàn)多文件上傳。

實(shí)例代碼:

html:

<!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>

php代碼:

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

  }
 }
}

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

相關(guān)文章

最新評(píng)論

霍山县| 昂仁县| 双鸭山市| 合山市| 正镶白旗| 西青区| 雷州市| 凤台县| 宁河县| 郎溪县| 凤凰县| 中西区| 嵩明县| 仁化县| 建阳市| 信宜市| 彩票| 清涧县| 钟祥市| 赤壁市| 信阳市| 台北市| 开远市| 常德市| 阜平县| 富宁县| 吉林市| 财经| 昆山市| 南投县| 洱源县| 沂水县| 阿图什市| 永嘉县| 吉林市| 瓮安县| 年辖:市辖区| 宜兴市| 宣恩县| 梁平县| 阿荣旗|