This commit is contained in:
parent
a6c7571ccc
commit
08e42ae7ad
|
@ -128,7 +128,7 @@
|
|||
<a class="list" href="javascript:;">
|
||||
<input id="file" type="file" name="myfile" onchange="UpladFile();" /><span>选择文件</span>
|
||||
</a>
|
||||
<button class="btn" type="button" onclick="sub();">上传</button>
|
||||
|
||||
|
||||
</p>
|
||||
<!--显示消失-->
|
||||
|
@ -215,37 +215,35 @@
|
|||
$(".el-upload-list").css("display", "block");
|
||||
$(".el-upload-list li").css("border", "1px solid #20a0ff");
|
||||
$("#videoName").text(fileObj.name);
|
||||
var fileObj = document.getElementById("file").files[0]; // js 获取文件对象
|
||||
if (fileObj == undefined || fileObj == "") {
|
||||
alert("请选择文件");
|
||||
return false;
|
||||
};
|
||||
var imagSize = document.getElementById("file").files[0].size;
|
||||
if (imagSize > 1024 * 1024 * 10) {
|
||||
alert("视频大小为:" + (imagSize / (1024 * 1024)).toFixed(2) + "M,超出了上传大小," + "请选择3M以内的视频!");
|
||||
return false;
|
||||
}
|
||||
var url = "mgt/upload"; // 接收上传文件的后台地址
|
||||
var form = new FormData(); // FormData 对象
|
||||
form.append("mf", fileObj); // 文件对象
|
||||
xhr = new XMLHttpRequest(); // XMLHttpRequest 对象
|
||||
xhr.open("post", url, true); //post方式,url为服务器请求地址,true 该参数规定请求是否异步处理。
|
||||
xhr.onload = uploadComplete; //请求完成
|
||||
xhr.onerror = uploadFailed; //请求失败
|
||||
xhr.upload.onprogress = progressFunction; //【上传进度调用方法实现】
|
||||
xhr.upload.onloadstart = function () { //上传开始执行方法
|
||||
ot = new Date().getTime(); //设置上传开始时间
|
||||
oloaded = 0; //设置上传开始时,以上传的文件大小为0
|
||||
};
|
||||
xhr.send(form); //开始上传,发送form数据
|
||||
} else {
|
||||
alert("请选择文件");
|
||||
}
|
||||
}
|
||||
|
||||
/*点击提交*/
|
||||
function sub() {
|
||||
var fileObj = document.getElementById("file").files[0]; // js 获取文件对象
|
||||
if (fileObj == undefined || fileObj == "") {
|
||||
alert("请选择文件");
|
||||
return false;
|
||||
};
|
||||
var imagSize = document.getElementById("file").files[0].size;
|
||||
if (imagSize > 1024 * 1024 * 10) {
|
||||
alert("视频大小为:" + (imagSize / (1024 * 1024)).toFixed(2) + "M,超出了上传大小," + "请选择3M以内的视频!");
|
||||
return false;
|
||||
}
|
||||
var url = "mgt/upload"; // 接收上传文件的后台地址
|
||||
var form = new FormData(); // FormData 对象
|
||||
form.append("mf",fileObj); // 文件对象
|
||||
xhr = new XMLHttpRequest(); // XMLHttpRequest 对象
|
||||
xhr.open("post", url, true); //post方式,url为服务器请求地址,true 该参数规定请求是否异步处理。
|
||||
xhr.onload = uploadComplete; //请求完成
|
||||
xhr.onerror = uploadFailed; //请求失败
|
||||
xhr.upload.onprogress = progressFunction; //【上传进度调用方法实现】
|
||||
xhr.upload.onloadstart = function () { //上传开始执行方法
|
||||
ot = new Date().getTime(); //设置上传开始时间
|
||||
oloaded = 0; //设置上传开始时,以上传的文件大小为0
|
||||
};
|
||||
xhr.send(form); //开始上传,发送form数据
|
||||
}
|
||||
|
||||
|
||||
//上传进度实现方法,上传过程中会频繁调用该方法
|
||||
function progressFunction(evt) {
|
||||
|
|
Loading…
Reference in New Issue