多文件上传
来源:互联网 发布:男生不追女生 知乎 编辑:程序博客网 时间:2024/06/13 09:46
视图层
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <title>xhr2</title> </head> <body> <div style="text-align:center;margin:100px"> <input type="file" id="file" name="file" multiple="multiple"> <button onclick="xhr2()">多文件上传</button> </div> <script> function xhr2(){ var xhr = new XMLHttpRequest();//第一步 //定义表单变量 var file = document.getElementById('file').files; //console.log(file.length); //新建一个FormData对象 var formData = new FormData(); //++++++++++ //追加文件数据 for(i=0;i<file.length;i++){ formData.append("file["+i+"]", file[i]); //++++++++++ } //formData.append("file", file[0]); //++++++++++ //post方式 xhr.open('POST', 'xhr2.php'); //第二步骤 //发送请求 xhr.send(formData); //第三步骤 //ajax返回 xhr.onreadystatechange = function(){ //第四步 if ( xhr.readyState == 4 && xhr.status == 200 ) { console.log( xhr.responseText ); } }; //设置超时时间 xhr.timeout = 100000; xhr.ontimeout = function(event){ alert('请求超时!'); } } </script> </body> </html>
控制器
<?php print_r($_FILES["file"]); for($i=0;$i<count($_FILES["file"]['name']);$i++){ $name=$_FILES["file"]["name"][$i]; move_uploaded_file($_FILES["file"]["tmp_name"][$i],iconv("UTF-8","gb2312",$name)); } ?>
0 0
- 文件上传(多文件)
- asp.net文件上传,多文件上传。
- 单文件上传、多文件上传
- struts2文件上传与多文件上传
- 单文件上传和多文件上传
- PHP文件上传功能 -- 多文件上传
- struts2文件上传(多文件上传)
- SpringMVC文件上传 多文件上传实例
- Struts2之文件上传,多文件上传
- SpringMVC文件上传 多文件上传实例
- 文件上传及多文件上传
- Spring boot 文件上传(多文件上传)
- Struts文件上传--2.多文件上传
- spring boot文件上传【多文件上传】
- FastDFS上传文件二 : 多文件上传
- 多文件上传
- 单/多文件上传
- 多个文件上传
- Git同步Fork代码
- U盘装系统
- 【Android + OpenCV】博客集
- 横向滑动导航条可点击滑动
- Error: Could not create the Java Virtual Machine
- 多文件上传
- Mahout源码目录说明
- win10下JDK8的安装与环境配置
- Unity3D游戏开发框架-FSM状态机的实现
- android 计时器的三种实现(Chronometer、Timer、handler)
- 【HDU 杭电OJ 1257 最少拦截系统】
- PHP 中文 转UNICODE, JS 将UNICODE转为GBK
- 详解传参时的SQL多条件模糊查询(VS2012)
- HDU-1257-最少拦截系统【LIS】