input[type="file"] multiple怎么上传啊?

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

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

那要是

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

传到后台改怎么写啊?

后台是PHP

阅读 5.4k
2 个回答

stackoverflow 搬运工
http://stackoverflow.com/questions/2704314/multiple-file-upload-in-php

HTML:

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

PHP:

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

// Loop through each file
for($i=0; $i<$total; $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

    }
  }
}

var_dump($_FLIE);
把变量打印出来看看结构就知道怎么接受了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题