123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- document.write("<script language=javascript src='jquery-1.4.4.min.js'></script>");
- var xmlHttpRequest;
- var ot;
- var oloaded;
- function createXmlHttpRequest() {
- if (window.ActiveXObject) {
- return new ActiveXObject("Microsoft.XMLHTTP");
- } else if (window.XMLHttpRequest) {
- return new XMLHttpRequest();
- }
- }
- function dataURLtoFile(dataurl, filename) {
-
-
- var bstr = atob(dataurl);
- var n = bstr.length;
- var u8arr = new Uint8Array(n);
- while (n--) {
- u8arr[n] = bstr.charCodeAt(n);
- }
- var suffix = filename.substring(filename.length - 3, filename.length);
- if (suffix == "jpg" || suffix == "JPG")
- return new File([u8arr], filename, { type: 'image/jpg' });
- if (suffix == "png" || suffix == "PNG")
- return new File([u8arr], filename, { type: 'image/png' });
- if (suffix == "tif" || suffix == "TIF")
- return new File([u8arr], filename, { type: 'image/tiff' });
- if (suffix == "pdf" || suffix == "PDF")
- new File([u8arr], filename, { type: 'application/pdf' });
- return new File([u8arr], filename, { type: 'application/jpg' });
- }
- function progressFunction(evt) {
- var progressBar = document.getElementById("progressBar");
- var percentageDiv = document.getElementById("percentage");
-
- if (evt.lengthComputable) {
- progressBar.max = evt.total;
- progressBar.value = evt.loaded;
- percentageDiv.innerHTML = Math.round(evt.loaded / evt.total * 100) + "%";
- }
- var time = document.getElementById("time");
- var nt = new Date().getTime();
- var pertime = (nt - ot) / 1000;
- ot = new Date().getTime();
- var perload = evt.loaded - oloaded;
- oloaded = evt.loaded;
-
- var speed = perload / pertime;
- var bspeed = speed;
- var units = 'b/s';
- if (speed / 1024 > 1) {
- speed = speed / 1024;
- units = 'k/s';
- }
- if (speed / 1024 > 1) {
- speed = speed / 1024;
- units = 'M/s';
- }
- speed = speed.toFixed(1);
-
- var resttime = ((evt.total - evt.loaded) / bspeed).toFixed(1);
- time.innerHTML = ',速度:' + speed + units + ',剩余时间:' + resttime + 's';
- if (bspeed == 0)
- time.innerHTML = '上传已取消';
- }
- function uploadComplete(evt) {
-
- alert("上传成功");
- }
- function uploadFailed(evt) {
-
-
- }
- function cancleUploadFile() {
- xhr.abort();
- }
- function UpladFile(url, base64data, fileName, callback) {
- var fileObj = dataURLtoFile(base64data, fileName);
-
- var fm = document.forms[0];
- var form = new FormData(fm);
- form.append("file", fileObj);
- xmlHttpRequest = createXmlHttpRequest();
- xmlHttpRequest.open("post", url, true);
- xmlHttpRequest.onreadystatechange = function () {
- if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
- var iRestStr = xmlHttpRequest.responseText;
- callback(iRestStr);
-
- }
- };
-
-
-
-
-
-
-
- xmlHttpRequest.send(form);
- }
|