html5批量大文件切割上传,AJAX-----16HTML5实现大文件切割上传(示例代码)

Document

/*我们用到的api有Blob,他的file里面有slice方法可以截取二进制对象的一部分。。

而且我们需要修改php.ini文件,

upload_max_filesize = 20M ---上传文件,单个文件的最大值

post_max_size = 20M post方式最大上传20M*/

functionbfbs(bfb){varpro=document.getElementsByTagName(\'progress\')[0];

pro.style.display= \'block\';

pro.setAttribute(\'value\',bfb);varsd=document.getElementById(\'sd\');

sd.innerHTML=bfb+\'%\';

}varclock= null;

xhr= newXMLHttpRequest();functionupgo(){

clock=window.setInterval(selefile,1000);

}varselefile=(function(){

const LENGTH= 10 * 1024 * 1024;//每次切割10M

varsta= 0;varend=sta+LENGTH;varflag= false;//标识上一块正在上传中...

varblob= null;varfd= null;varxhr= null;varbfb= 0;return(function(){if(flag== true){return;

}varup_file=document.getElementsByTagName(\'input\')[0].files[0];//如果sta大于up_file.size那么就结束咯

if(sta>up_file.size){

clearInterval(clock);return false;

}

blob=up_file.slice(sta,end);varfd= newFormData();

fd.append(\'part\',blob);//请求后端

up(fd);

sta=end;

end=sta+LENGTH;

flag= false;//进队条

bfb=Math.ceil(100 *end/up_file.size);

bfb> 100 ?bfb= 100: bfb=bfb;

bfbs(bfb);

});

})();functionup(fd){

xhr.open(\'POST\',\'./14.php\',false);

xhr.send(fd);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值