上传图片

function UpLoadImage()
{
$('#UploadForm').attr("action", "/sation/handlers/UploadImage.ashx");
$('#divBillboardImage').parent().appendTo($('#UploadForm'));
$("#UploadForm").ajaxSubmit({
url: "/sation/handlers/UploadImage.ashx",
type: "post",
dataType: "json",
success: function(data)
{
if (data.resault == "ok") {
$("#U14").append("<li><div><img width='120px' url='"+data .SavePath+"' class='image1' height='120px' src='" + data.ServerPath + "'/><br/><a href='javascript:void(0)' onclick='DelImage(this,1)' >删除</a></div></li>");
}
else if (data.resault == "error") {
alert(data.msg);
};
},
error:function ()
{
alert ("异常");
}
});

}
function DelImage(obj,index)
{
var li=obj .parentNode.parentNode;
li .remove();
var images="";
$(".image"+index).each(function (){
images +=$(this ).attr("url")+"|";
})
alert (images);
alert ($(".image"+index).length);
$("#<%=HiddenImages.ClientID %>").val(Images);
$.ajax({
type: "get",
url: "/sation/handlers/ServicesItem/UpdateImage.ashx",
data:{"Images":Images,"id":<%=ServiceItemID%>},
success: function(msg) {
if (msg == "ok") {
alert("删除成功");
// window.location.href=location .href ;
} else {
alert("删除成功");
}
},
error: function(msg) {
alert("请求异常");
}
});
}
}

context.Response.ContentType = "text/plain";
HttpPostedFile File = context.Request.Files["tempImage"];
if (File != null)
{
FileSettingEntity fileVaild = FileManger.GetFileSetting((int)ESourceType.fromStationImg);
if (File.ContentLength > fileVaild.Length)
{
context.Response.Write("{"resault":"error","msg":"" + "上传的图片大小不能超过" + fileVaild.Length / 1024 + "kb!" + ""}");
return;
}
FileEntity fentity = null;
try
{
fentity = Gasgoo.B2C.Common.FileUpload.ReceptionUploadFixedGIPImage(File, ESourceType.fromStationImg, 0, UserId, false);
}
catch
{
context.Response.Write("{"resault":"error","msg":"请上传.jpeg|.jpg|.gif格式文件!"}");
return;
}
string Path = FileFactory.GetFilePathByFileArray(fentity.SavePath, ESourceType.fromStationImg);
string ImgFile = string.Empty;
ImgFile = "{"resault":"ok",";
ImgFile += ""msg":"",";
ImgFile += ""SavePath":"" + fentity.SavePath + "",";
ImgFile += ""ServerPath":"" + Path + """;
ImgFile += "}";
context.Response.Write(ImgFile);
}

原文地址:https://www.cnblogs.com/q101301/p/3939487.html