文件上传
来源:互联网 发布:android数据库操作 编辑:程序博客网 时间:2024/06/07 04:02
function uploadFile(){
if(!checkImgType($("#file"))){
return false;
}else if(!checkSize($("#file"))){
return false;
}
$.ajaxFileUpload({
url:contextPath + '/editor/uploadJson/upload',
secureuri:false,
fileElementId:'file',
dataType: 'json',
error: function (data, status, e){
alert(data);
},
success: function (data, status){
if(status!="success"){
alert("仅支持RAR格式,大小不超过5M");
}else{
alert("上传成功");
var path = data.url.split("photo/");
var contractPath = path[path.length-1];
vueEdit.entity.contractPath = contractPath;
}
}
});
}
function checkImgType(ths) {
try {
var obj_file = $(ths).get(0).files;
for(var i=0;i<obj_file.length;i++){
if (!/\.(RAR)$/.test(obj_file[i].name.toUpperCase())) {
alert("仅支持RAR格式");
$(ths).val("");
return false;
}
}
} catch (e) {
}
return true;
}
var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
function checkSize(target){
var fileSize = 0;
fileSize = target[0].files[0].size;
var size = fileSize / 1024 / 1024;
if (size > 5) {
alert("附件不能大于5M");
var obj = document.getElementById('file') ;
obj.outerHTML=obj.outerHTML;
return false;
}else{
return true;
}
}
if(!checkImgType($("#file"))){
return false;
}else if(!checkSize($("#file"))){
return false;
}
$.ajaxFileUpload({
url:contextPath + '/editor/uploadJson/upload',
secureuri:false,
fileElementId:'file',
dataType: 'json',
error: function (data, status, e){
alert(data);
},
success: function (data, status){
if(status!="success"){
alert("仅支持RAR格式,大小不超过5M");
}else{
alert("上传成功");
var path = data.url.split("photo/");
var contractPath = path[path.length-1];
vueEdit.entity.contractPath = contractPath;
}
}
});
}
function checkImgType(ths) {
try {
var obj_file = $(ths).get(0).files;
for(var i=0;i<obj_file.length;i++){
if (!/\.(RAR)$/.test(obj_file[i].name.toUpperCase())) {
alert("仅支持RAR格式");
$(ths).val("");
return false;
}
}
} catch (e) {
}
return true;
}
var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
function checkSize(target){
var fileSize = 0;
fileSize = target[0].files[0].size;
var size = fileSize / 1024 / 1024;
if (size > 5) {
alert("附件不能大于5M");
var obj = document.getElementById('file') ;
obj.outerHTML=obj.outerHTML;
return false;
}else{
return true;
}
}
阅读全文
0 0
- 文件上传---文件上传
- 上传文件
- 文件上传
- 上传文件
- 文件上传
- 文件上传
- 上传文件
- 上传文件
- 文件上传
- 文件上传
- 文件上传
- 文件上传
- 文件上传
- 文件上传
- 文件上传
- 上传文件
- 文件上传
- 文件上传
- Springboot+logback集成ELK处理日志实例
- 扫码枪抓取数据
- 反射
- mysql和eclipse插入语句乱码问题
- JS复制对象、数组
- 文件上传
- MVVM
- <p>标签首行缩进2字符
- 数据结构课程设计----火警与医疗系统
- AI留给人类的时间已不多:《未来简史》作者赫拉利Nature来信
- nginx配置讲解
- Hacking Enums and Modifying "final static" Fields
- 3、html列表
- handsontable测试