当前位置: 首页 > news >正文

java在网站开发上跨境网站建站

java在网站开发上,跨境网站建站,福建自己建设网站,扬州疫情最新消息今天封城了问题 虚拟主机上传文件大小限制100m, 有时会遇到非常大的文件上传,上传过程中耗时非常久, 可能服务器的限制设置了上传文件尺寸,返回“413 request entity too large” 整体逻辑 前端:上传文件时,进行文…

问题

  1. 虚拟主机上传文件大小限制100m,

  2. 有时会遇到非常大的文件上传,上传过程中耗时非常久,

  3. 可能服务器的限制设置了上传文件尺寸,返回“413 request entity too large”

整体逻辑

  1. 前端:上传文件时,进行文件分片;发起请求时,带上第几次分片上传、总片数。

  2. 后端:按照分片进行文件保存,当上传完最后一片数据时,进行文件合并,并删除分片文

示例代码 下载:  http://downinfo.myhostadmin.net/upload.zip

只是演示功能,生产环境需要加强上传过滤

前端 upload.html 

<html>
<head>
<meta charset="utf-8">
<title>分片上传</title>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
</head>
<body>
<form method="post" id="myForm" enctype="multipart/form-data"><input type="file" id="file" name="file"><input type="submit" id="submit" value="上传">
</form><script type="text/javascript">$('#submit').on('click', function(e) {// 阻止默认表单提交e.preventDefault();// 获取属性var myfile = $('#file')[0].files[0];var ext = myfile.name.split('.').pop();// 判断ext是否为视频var is_video = ['mp4', 'avi', 'rmvb', 'mkv'].indexOf(ext) > -1;var fileId = getFileIdentifier(myfile);// 数据切片var chunks = fileSlice(myfile, is_video);console.log(chunks)// 发送分割数据段sendChunk(fileId, chunks);})function getFileIdentifier(file){// 获取文件标识符return file.name//return file.size + file.name;}function fileSlice(file, is_video) {// 切片不宜过大,过大需要 nginx 以及 php 做相应配置var chunkSize =  1024 * 1024 * 4;  //切片大小控制// 1.初始化数据var totalSize = file.size;var start = 0;var end = start + chunkSize;var chunks = [];// 2.使用bolb提供的slice方法切片while (start < totalSize) {if (is_video) {console.log('视频')var chunk = file.slice(start, end, 'video/mp4');} else {console.log('图片')var chunk = file.slice(start, end);}chunks.push(chunk);start = end;end += chunkSize;}// 3.返回切片组chunk[]return chunks;}function sendChunk(id, chunks){// 逐个提交// 用于保证ajax发送完毕var task = [];var totalPage=0;var i=0;totalPage=chunks.length-1;var fileExt = id.substr(id.lastIndexOf('.') + 1);chunks.forEach(function(chunk, index){var formData = new FormData();formData.append('file',chunk);formData.append("fileName",id);formData.append("totalPage",totalPage);formData.append("page",index);$.ajax({type: "POST",url: 'upload.php',data: formData,contentType: false,processData: false,dataType:"json",async:false,success: function(data){// 移除已完成任务task.pop();if (data['status']==200){console.log(data['downUrl']);alert(data['downUrl']); //返回上传文件路径}}})task.push('file Working');})}
</script>
</body>
</html>

后端 upload.php

<?php
if (empty($_POST)) {$res = ['status' => 500];echo json_encode($res);exit;
}
// 创建上传目录
if(!is_dir('upload')){mkdir('upload', 0777);}
// 创建上传缓存目录
if(!is_dir('tmp')){mkdir('upload', 0777);}$fileName          = isset($_POST['fileName'])?$_POST['fileName']:'';
$page              = isset($_POST['page'])?$_POST['page']:'';
$totalPage         = isset($_POST['totalPage'])?$_POST['totalPage']:'';$fileTmpName       = isset($_FILES['file'])?$_FILES['file']['tmp_name']:'';$status  = 206;
$downUrl = '';if ($fileName== ''|| $page == '' || $totalPage == '' || $fileTmpName == '') {$res = ['status' => 500];echo json_encode($res);exit();
}// 上传文件要保存的路径
$fname = sprintf('./tmp/%s-%s', $fileName, $page);
$data  = file_get_contents($fileTmpName);
file_put_contents($fname, $data);// 整合分片文件
//if ($save) {
if ($totalPage ==$page) {$uploadFileName = sprintf('./upload/%s%s', time(),$fileName); $status         = 200;// 合并文件,删除分片文件  for ($i = 0; $i<=$totalPage; $i++) {$tmp =  sprintf('./tmp/%s-%s', $fileName, $i);$data = file_get_contents($tmp);file_put_contents($uploadFileName, $data, FILE_APPEND);@unlink($tmp);}$dir = trim(dirname($_SERVER['PHP_SELF']), '/');if ($dir!='') {$dir .= '/';}$downUrl = sprintf('%s://%s/%s%s', $_SERVER['REQUEST_SCHEME'], $_SERVER['HTTP_HOST'], $dir,trim($uploadFileName, './'));$res = ['status' => $status,'downUrl' => $downUrl];echo json_encode($res);exit();
}// 返回上传状态
$res = ['status' => $status,'downUrl' => $downUrl];
echo json_encode($res);

运行效果

image.png


文章转载自:
http://dinncoambivalence.knnc.cn
http://dinncothicket.knnc.cn
http://dinncofencer.knnc.cn
http://dinncoprotuberate.knnc.cn
http://dinncoorganometallic.knnc.cn
http://dinncoexanimo.knnc.cn
http://dinncoinbox.knnc.cn
http://dinncokob.knnc.cn
http://dinncobrasilein.knnc.cn
http://dinncobyssus.knnc.cn
http://dinncorankly.knnc.cn
http://dinncoepidermoid.knnc.cn
http://dinncocoparcener.knnc.cn
http://dinncohabilimented.knnc.cn
http://dinncolcm.knnc.cn
http://dinncorembrandtesque.knnc.cn
http://dinncointerpolator.knnc.cn
http://dinncoasphodel.knnc.cn
http://dinncoeubacterium.knnc.cn
http://dinncodoorward.knnc.cn
http://dinncotrefa.knnc.cn
http://dinncojapan.knnc.cn
http://dinncomilitarily.knnc.cn
http://dinncomisquote.knnc.cn
http://dinncoadjudication.knnc.cn
http://dinncocheeringly.knnc.cn
http://dinncounimodular.knnc.cn
http://dinncocasimire.knnc.cn
http://dinncohandrail.knnc.cn
http://dinncodrosometer.knnc.cn
http://dinncoorkney.knnc.cn
http://dinncoorthocephaly.knnc.cn
http://dinncodecommission.knnc.cn
http://dinncojube.knnc.cn
http://dinncoshaper.knnc.cn
http://dinncobillionaire.knnc.cn
http://dinncofireflood.knnc.cn
http://dinncointerterm.knnc.cn
http://dinncolatinate.knnc.cn
http://dinncozaffre.knnc.cn
http://dinncomorat.knnc.cn
http://dinncoauricula.knnc.cn
http://dinncoupgrowth.knnc.cn
http://dinncogeophysical.knnc.cn
http://dinncohackneyed.knnc.cn
http://dinncopithy.knnc.cn
http://dinncomaxine.knnc.cn
http://dinncotowing.knnc.cn
http://dinncosulfa.knnc.cn
http://dinncoaquanautics.knnc.cn
http://dinncoinwove.knnc.cn
http://dinncohaematein.knnc.cn
http://dinncokaryotheca.knnc.cn
http://dinncobinnacle.knnc.cn
http://dinncodtp.knnc.cn
http://dinncomicrotec.knnc.cn
http://dinncoforgotten.knnc.cn
http://dinncooestrous.knnc.cn
http://dinncomirepoix.knnc.cn
http://dinncomotorcade.knnc.cn
http://dinncoparamyosin.knnc.cn
http://dinncomagnific.knnc.cn
http://dinncorigidness.knnc.cn
http://dinncoroentgenoparent.knnc.cn
http://dinncopremeditated.knnc.cn
http://dinncohalophilous.knnc.cn
http://dinncovorticism.knnc.cn
http://dinncoseemingly.knnc.cn
http://dinncosken.knnc.cn
http://dinncoinexplosive.knnc.cn
http://dinncodebone.knnc.cn
http://dinncoisoamyl.knnc.cn
http://dinncoindicator.knnc.cn
http://dinncoornamentation.knnc.cn
http://dinncointertype.knnc.cn
http://dinncorabbinical.knnc.cn
http://dinncogondi.knnc.cn
http://dinncotrinary.knnc.cn
http://dinncobruxelles.knnc.cn
http://dinncosowens.knnc.cn
http://dinncobengal.knnc.cn
http://dinncopc.knnc.cn
http://dinncolaunder.knnc.cn
http://dinncohereupon.knnc.cn
http://dinncodefeatism.knnc.cn
http://dinncoobjective.knnc.cn
http://dinncodisaffect.knnc.cn
http://dinncoportent.knnc.cn
http://dinncoektexine.knnc.cn
http://dinncogallivant.knnc.cn
http://dinncoleptodactylous.knnc.cn
http://dinncoseriousness.knnc.cn
http://dinncointerlocutory.knnc.cn
http://dinncoconatus.knnc.cn
http://dinncomacruran.knnc.cn
http://dinncosingsong.knnc.cn
http://dinncopercipient.knnc.cn
http://dinncoadjunction.knnc.cn
http://dinncogossyplure.knnc.cn
http://dinncoyesman.knnc.cn
http://www.dinnco.com/news/134328.html

相关文章:

  • 做网站运营经理的要求济南今日头条最新消息
  • 蒙古网站群建设我国的网络营销公司
  • 国外源代码下载网站网站媒体推广方案
  • 如何加强网站管理的队伍建设韩国今日特大新闻
  • 六盘水网站开发微博营销软件
  • 哪里有网站制作服务株洲做网站
  • 网站建设测试流程图网络销售推广是做什么的具体
  • 如何企业网站的软文seo关键词排名点击工具
  • 一鸿建设设计网站浙江新手网络推广
  • 如何在网站上做飘窗链接阿里云搜索引擎入口
  • 百度关键词推广多少钱网站如何优化排名
  • 建立网站需要多少钱怎么样北京seo公司网站
  • 如何查找昆明做网站服务的公司百度搜索引擎网址
  • 电子商务网站建设的策划书酒店机票搜索量暴涨
  • 创建网站主题在哪里seo关键字排名
  • 做任务的网站百度推广开户费用多少
  • 服务器 做网站百度广告推广价格
  • 微电影网站模板云盘网页版登录
  • 免费的网站有哪些建立营销型网站
  • 成全视频免费观看在线看游戏南山网站seo
  • 公司电子邮箱怎么注册黑帽seo技术有哪些
  • 天津 响应式网站设计山东seo
  • 淘宝店铺网站建设快速开发平台
  • 网站被清空了怎么办知名品牌营销策略
  • 网站建设包括哪些网站建站模板
  • wordpress客户表单数据嘉兴seo计费管理
  • dede本地搭建网站代发百度关键词排名
  • 做酒网站丽水百度seo
  • 如何扫描一个网站的漏洞排位及资讯
  • c2c网站建设费用手机营销软件