使用formdata的多文件上传  废话少说 直接上代码

1 JS部分

//选择文件后的处理
function handleFileSelect()
{
var exerciseid=$("#exerciseid").val();
var workerid=$("#workerid").val();
var pic_kind=$("#pic_kind").val();
//var pic_file = $('#pic_file')[0].files[0]; var formData = new FormData(); //formData.append("pic_file",$('#pic_file')[0].files[0]); var filesize=$('#pic_file')[].files.size; alert(filesize); for(var i=; i<$('#pic_file')[].files.length;i++){
alert($('#pic_file')[].files[i].size);
formData.append('file[]', $('#pic_file')[].files[i]);
} formData.append("pic_kind", pic_kind);
formData.append("exerciseid", exerciseid);
formData.append("workerid", workerid); $.ajax({
url: "{:U('Publishset/newUpload')}",
dataType:'json',
type:'POST',
data: formData,
processData : false, // 使数据不做处理
contentType : false, // 不要设置Content-Type请求头
xhr: function(){ //获取ajaxSettings中的xhr对象,为它的upload属性绑定progress事件的处理函数
myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){ //检查upload属性是否存在
//绑定progress事件的回调函数
myXhr.upload.addEventListener('progress',aprogressHandlingFunction, false);
}
return myXhr; //xhr对象返回给jQuery使用
},
success: function(data){ $('#ap').val();
$('#aprogress').html(''); showExerciseImage(exerciseid);
//if (data) { // alert('上传成功!');
//} },
error:function(response){
console.log(response);
}
}); } //上传进度回调函数:
function aprogressHandlingFunction(e) {
if (e.lengthComputable) {
$('#ap').attr({value : e.loaded, max : e.total}); //更新数据到进度条
var percent = e.loaded/e.total*;
$('#aprogress').html(percent.toFixed() + "%");
}
}

2 html 部分

 <input class="file" id="pic_file" multiple type="file" onchange="handleFileSelect(event)" style="display:none;">

3 PHP部分

 public function newUpload()
{ //上传配置
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize= ;// 设置附件上传大小
$upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath='./uploads/inittestimg/'; // 设置附件上传根目录 $upload->savePath=''; // 设置附件上传(子)目录 //上传文件
$info=$upload->upload(); //参数获取
$exerciseid=$_POST["exerciseid"];
$kind=$_POST['pic_kind'];
$workerid=$_POST['workerid']; if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());
}else{// 上传成功 获取上传文件信息 $images = M('initimages'); //循环入库
foreach($info as $file){
$imgarr['exerciseid']=$exerciseid;
$imgarr['src']='./uploads/inittestimg/'.$file['savepath'].$file['savename'];
$imgarr['kind']=$kind;
$imgarr['lastreadtime']=time(); //文件名
//$imgarr['orderid']=str_replace(strrchr($info['pic_file']['name'], "."),"",$info['pic_file']['name']);
$imgarr['orderid']=$file['name']; $images->add($imgarr);
} } echo ;
}

thinkphp3.2.3使用formdata的多文件上传的更多相关文章

  1. Java Web使用Html5 FormData实现多文件上传

    前一阵子,迭代一个线上的项目,其中有一个图片上传的功能,之前用的ajaxfileupload.js来实现上传的,不过由于ajaxfileupload.js,默认是单文件上传(虽然可以通过修改源码的方法 ...

  2. jQuery用FormData对象实现文件上传以及如何通过ajax下载文件

    之前在Vue的项目里面用到过文件上传,封装好的组件用起来比较顺手,查询Element-UI文档,十八般武器样样都有,一顿操作猛如虎,一看--跑偏了(⊙o⊙)-,我的意思就是用框架实现比较简单,但是如果 ...

  3. WebApi实现Ajax模拟Multipart/form-data方式多文件上传

    前端页面代码: <input type="file" class="file_control" /><br /> <input t ...

  4. multipart/form-data请求与文件上传

    要上传文件,需要用post方法,并且设置enctype为multipart/form-data. <form action="/upload" method="po ...

  5. multipart/form-data请求与文件上传的细节

    <!DOCTYPE html><html><head lang="en">  <meta charset="UTF-8" ...

  6. vue axios 与 FormData 结合 提交文件 上传文件

    ---再利用Vue.axios.FormData做上传文件时,遇到一个问题,后台虽然接收到请求,但是将文件类型识别成了字符串,所以,web端一直报500,结果是自己大意了. 1.因为使用了new  F ...

  7. tp5结合FormData实现ajax文件上传

    或者使用: 下面使用jquery.form.js的表单插件来提交表单

  8. FormData+Ajax 实现多文件上传 学习使用FormData对象

    FormData对象是为序列化表以及创建与表单格式相同的数据(当然是用于XHR传输)提供便利. 今天我们使用dropzone和FormData实现多文件上传功能. var SAMP = null; / ...

  9. vue使用formData进行文件上传

    本文为博主原创,未经允许不得转载 1.vue页面 <ux-form ref="formRef" layout="vertical"> <ux- ...

随机推荐

  1. Android 中指纹识别

    Android从6.0系统开始就支持指纹认证功能了,指纹功能还需要有硬件支持才行 指纹与手机系统设置的指纹进行匹配 如图: 在LoginActivity 中弹出指纹验证Fragment,验证成功进入M ...

  2. HeadFirst设计模式---装饰者

    定义装饰者模式 装饰者模式动态地将责任附加到对象上,若要扩展功能,装饰者提供了比继承更有弹性的替代方案.这句话摘自书中,给人读得很生硬难懂.通俗地来说,装饰者和被装饰者有相同的父类,装饰者的行为组装着 ...

  3. Facebook发布全新JavaScript引擎:Hermes

    摘要: JS引擎开始升级了... 原文:技术栈中的爱马仕?Facebook发布全新JavaScript引擎:Hermes 作者:Carson_Ho Fundebug经授权转载,版权归原作者所有. 前言 ...

  4. Windows 2003 IIS6.0下配置ASP+MySQL+PHP+ISAPI_Rewrite+Zend+Xcache

    windows 2003,自己买吧... 安装IIS6.0:安装系统后在"控制面板"->"添加或删除程序"->"添加/删除Windows组 ...

  5. linux date 设置系统时间

    设置 系统时间 注意时间格式 date  -s "date" [root@localhost c]# date -s "2019-05-29 10:58:00" ...

  6. 静态文件 static

    一.常见的形式 前面初步搭建Django开局时候就 在 项目路径下 建立了statics 文件夹,然后在 settings.py  文件的末尾添加了 statics 文件夹的绝对路径. # 这个可以给 ...

  7. modbus_tk模块

    modbus_tk模块 通过modbus-RTU 读取地址,调用后返回反馈数值和故障信息. modbus_tk模块安装 pip install pymodbus_tk 下面代码功能:读取地址为0x42 ...

  8. Shel脚本-初步入门之《03》

    Shel脚本-初步入门-Shell 脚本在 Linux 运维工作中的地位 3.Shell 脚本在 Linux 运维工作中的地位 Shell 脚本语言很适合用于处理纯文本类型的数据,而 Linux 系统 ...

  9. Python:tarxjb简单、安全文件拷贝、传输

    tarxjb 简单.安全文件拷贝.传输 描述 通过python paramiko库实现简易ssh.sftp执行操作,从而实现文件的远程传输 Github 优点: 可靠传输,文件不易受损 安全传输,避免 ...

  10. 2019.6.11_MySQL进阶三:临时表

    临时表 临时表主要应用于保存一些临时数据.临时表只在当前连接可见.当关闭连接时,MySQL会自动删除表并且释放空间.临时表在MySQL 3.23版本中添加,低于 3.23版本就无法使用MySQL的临时 ...