国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

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

Original 2016-12-24 13:37:55 278
abstract:首先向大家介紹一下html5中file的multiple屬性定義和用法multiple 屬性規(guī)定輸入字段可選擇多個值。如果使用該屬性,則字段可接受多個值。實(shí)例:<form action="demo_form.asp" method="get">  Select images: <input&

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

定義和用法

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

實(shí)例:

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

   

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

了解了html5中file的multiple屬性,下面我們開始講解使用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
 
  }
 }
}

更多關(guān)于php 使用html5實(shí)現(xiàn)多文件上傳實(shí)例請關(guān)注PHP中文網(wǎng)(www.miracleart.cn)其它文章! 

Release Notes

Popular Entries