首頁 >後端開發 >php教程 >input[type='file'] multiple怎麼上傳啊?

input[type='file'] multiple怎麼上傳啊?

不言
不言原創
2018-05-28 10:16:562502瀏覽
<input type="file" name="some-img">

表單提交到伺服器,就是$_FILES["some-img"]

那要是

<input type="file" name="some-img[]" multiple>

傳到後台改怎麼寫啊?

後台是PHP

回覆內容:

<input type="file" name="some-img">

表單提交到伺服器,就是$_FILES["some-img"]

那要是

<input type="file" name="some-img[]" multiple>

傳到後台怎麼寫啊?

後台是PHP

HTML:

<input name="upload[]" type="file" multiple="multiple" />

PHP:

// Count # of uploaded files in array
$total = count($_FILES[&#39;upload&#39;][&#39;name&#39;]);

// Loop through each file
for($i=0; $i<$total; $i++) {
  //Get the temp file path
  $tmpFilePath = $_FILES[&#39;upload&#39;][&#39;tmp_name&#39;][$i];

  //Make sure we have a filepath
  if ($tmpFilePath != ""){
    //Setup our new file path
    $newFilePath = "./uploadFiles/" . $_FILES[&#39;upload&#39;][&#39;name&#39;][$i];

    //Upload the file into the temp dir
    if(move_uploaded_file($tmpFilePath, $newFilePath)) {

      //Handle other code here

    }
  }
}

var_dump($_FLIE);
變數印出來看看結構就知道怎麼印了

變數🎜
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn