var subUrl = "";
$("#file0").change(function() {//获取当前
var objUrl = getObjectURL(this.files[0]);
console.log(this.files[0])
obUrl=objUrl;
console.log("objUrl = " +objUrl);if(objUrl) {
$("#img0").attr("src", objUrl).show();
}else{
$("#img0").hide();
}
});
$(function() {
$(".file-3").bind(‘change‘, function() {
subUrl= $(this).val();
$(".yulan").show();
$(".file-3").val("");
});
$(".btn-3").click(function() {
$("#img-1").attr("src", obUrl);
$(".yulan").hide();
$(".file-3").parents(".uploader").find(".filename").val(subUrl);var basepath = "";var ClassID = $("#ClassID").val();var TeacherID = $("#TeacherID").val();var image = newImage();
image.crossOrigin= ‘‘;
image.src=obUrl;
image.οnlοad= function() {
basepath=getBase64Image(image);
basepath= basepath.replace(/^data:image\/(png|jpg);base64,/, "")//开始异步发送
$.ajax("/home/savenewsbackimage", {
data: JSON.stringify({ path: basepath, ClassID: ClassID, TeacherID: TeacherID }),
type:"POST", dataType: "text", contentType: "application/json;utf-8",
success:function(data) {
alert(data);
}
});
}
})
$(".btn-2").click(function() {
$(".yulan").hide();
})
});functionqd() {var objUrl = getObjectURL(this.files[0]);
obUrl=objUrl;
console.log("objUrl = " +objUrl);if(objUrl) {
$("#img0").attr("src", objUrl).show();
}else{
$("#img0").hide();
}
}functiongetObjectURL(file) {var url = null;if (window.createObjectURL != undefined) { //basic
url =window.createObjectURL(file);
}else if (window.URL != undefined) { //mozilla(firefox)
url =window.URL.createObjectURL(file);
}else if (window.webkitURL != undefined) { //webkit or chrome
url =window.webkitURL.createObjectURL(file);
}returnurl;
}//img转码base64
functiongetBase64Image(img) {var canvas = document.createElement("canvas");
canvas.width=img.width;
canvas.height=img.height;var ctx = canvas.getContext("2d");
ctx.drawImage(img,0, 0, img.width, img.height);var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();var dataURL = canvas.toDataURL("image/" +ext);returndataURL;
}