php - input[type="file"] multiple怎么上传啊?
本文介绍了php - input[type="file"] multiple怎么上传啊?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<input type="file" name="some-img">
表单提交到服务器,就是$_FILES["some-img"]
那要是
<input type="file" name="some-img[]" multiple>
传到后台改怎么写啊?
后台是PHP
解决方案
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
}
}
}
这篇关于php - input[type="file"] multiple怎么上传啊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文