上传图片2

<td rowspan="5">
<!--认证照片显示于此处-->
<img id="ConfirmimgLogo" src="../Images/photo.jpg" style=" 150px; height: 180px;" />
</td>

<td>
<!--照片上传功能在此处-->
<input type="file" id="ConfirmFileUpload_Logo" name="ConfirmFileUpload_Logo" style=" 180px" class="easyui-linkbutton" />
</td>

//$("#FileUpload_Logo").change(function () {
$("#FileUpload_Logo").live('change', function () {
$.ajaxFileUpload({
url: '/Club/Club.ashx?action=UpLoadImage&random=' + Math.random(),
secureuri: false,
fileElementId: 'FileUpload_Logo',
dataType: 'json',
data: { "isCreateThumbnail": "true", "Width": 55, "Height": 60, "Mode": "W" },
success: function (data, status) {
if (data.error == "true") {
AlertInfo('操作提示', '上传失败,请重新上传');
return false;
}
$("#hfLogo").val(data.path);
$("#imgLogo").attr("src", data.path);
},
error: function (data, status, e) {
AlertInfo('操作提示', '上传失败,请重新上传');
return false;
},
});
});

#region 上传图片
/// <summary>
/// 上传图片
/// </summary>
/// <returns></returns>
public void UpLoadImage(HttpContext hc)
{
bool isCreateThumbnail = GetRequest("isCreateThumbnail", false);
int Width = GetRequest("Width", 55);
int Height = GetRequest("Height", 60);
string Mode = GetRequest("Mode", "W");
//是否返回图片的宽高,默认是不返回
bool isReturnBigWidthHeight = GetRequest("isReturnBigWidthHeight", false);

hc.Response.ContentType = "text/html";
string result = "{error:'true'}";
try
{
HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
if (files == null && files.Count < 1)
{
hc.Response.Write(result);
return;
}
PicUploadResult picResult = UploadFile.UpLoadImage(files[0], isCreateThumbnail, Width, Height, Mode, isReturnBigWidthHeight);
picResult.BigPicturePath = picPathPrefix + picResult.BigPicturePath;
picResult.SmallPicturePath = picPathPrefix + picResult.SmallPicturePath;

hc.Response.Write("{error:'false',path:'" + picResult.BigPicturePath + "',smallPicPath:'" + picResult.SmallPicturePath + "',picWidht:'" + picResult.BigPicWidth + "',picHeight:'" + picResult.BigPicHeight + "'}");
}
catch (Exception ex)
{
hc.Response.Write(result);
}
}
#endregion

原文地址:https://www.cnblogs.com/ztf20/p/9886106.html