php中的多文件上传我想上传多个文件并将它们存储在一个文件夹中,获取路径并将其存储在数据库中.任何你想要做多个文件上传的好例子.。注:文件可以是任何类型的.。
3 回答
![?](http://img1.sycdn.imooc.com/545847d40001cbef02200220-100-100.jpg)
神不在的星期二
TA贡献1963条经验 获得超6个赞
输入名称必须定义为数组,即 name="inputName[]"
输入元素必须具有 multiple="multiple"
或者只是 multiple
在PHP文件中使用语法 "$_FILES['inputName']['param'][index]"
确保寻找 空文件名和路径
,数组可能包含 空字符串
..使用 array_filter()
在数数之前。
<input name="upload[]" type="file" multiple="multiple" />
//$files = array_filter($_FILES['upload']['name']); //something like that to be used before processing files. // Count # of uploaded files in array$total = count($_FILES['upload']['name']);// Loop through each filefor( $i=0 ; $i < $total ; $i++ ) { //Get the temp file path $tmpFilePath = $_FILES['upload']['tmp_name'][$i]; //Make sure we have a file path 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 } }}
![?](http://img1.sycdn.imooc.com/54584cb50001e5b302200220-100-100.jpg)
江户川乱折腾
TA贡献1851条经验 获得超5个赞
<input type='file' name='file[]' multiple>
<html><title>Upload</title><?php session_start(); $target=$_POST['directory']; if($target[strlen($target)-1]!='/') $target=$target.'/'; $count=0; foreach ($_FILES['file']['name'] as $filename) { $temp=$target; $tmp=$_FILES['file']['tmp_name'][$count]; $count=$count + 1; $temp=$temp.basename($filename); move_uploaded_file($tmp,$temp); $temp=''; $tmp=''; } header("location:../../views/upload.php");?></html>
$_FILES['file']['name'][0]
$_FILES['file']['name'][1]
- 3 回答
- 0 关注
- 420 浏览
添加回答
举报
0/150
提交
取消