62,242
社区成员




<script type="text/javascript">
var rPath = "";
$(function () {
UploadImg();
});
function UploadImg() {
$("#uploadify").uploadify({
'auto': true,
'swf': "../Common/Uploadify/uploadify.swf",
'uploader': 'UploadHandler.ashx?d=' + new Date(),
'queueID': 'fileQueue',
'fileObjName': 'upload',
'buttonText': '选择文件', //浏览按钮的文本,默认值:BROWSE 。
'progressData': 'percentage',
'formData': { 'action': 'upload', 'uppath': '../upfiles/temp', 'uid': 'admin' },
'preventCaching': true,
'width': '150',
'height': '35',
'fileTypeDesc': '支持的格式:', //在浏览窗口底部的文件类型下拉菜单中显示的文本
//'fileTypeExts': '*.jpg;*.jpge;*.gif;*.png', //允许上传的文件后缀
'fileTypeExts': '*.jpg;*.png',
'fileSizeLimit': '3MB',
'queueSizeLimit': 25,
'onUploadSuccess': function (file, data, response) {
rPath = JSON.parse(data).filepath;
//$("#image1").attr("src", result.filepath);
}
});
}
function HandlerImage() {
//$("#image1").attr("src", rPath); //这里直接显示是没问题的
//用ajax处理后就不能显示,显示一片空白
$.ajaxSettings.async = false; //即使加了同步也不起作用
$.getJSON("UploadHandler.ashx", { 'action': 'cutimage', 'uid': 'admin', 'filepath': rPath, 'sw': '300', 'sh': '300' },
function (result) {
if (result.statusCode == 200) {
alert(result.filepath); //返回的地址没问题,直接在浏览器中可查看到图片
$("#image1").attr("src", result.filepath);
}
});
}
</script>
string filepath = context.Request["filepath"];
string sW = context.Request["sw"];
string sH = context.Request["sh"];
filepath = context.Server.MapPath(filepath);
Stream stream = ImageMgr.FileToStream(filepath);
ImageMgr.ZoomAuto(stream, filepath, Convert.ToDouble(sW), Convert.ToDouble(sH), "", "");
stream.Close();
stream.Dispose();
string str = Success(filepath.Replace("\\", "\\\\"));
context.Response.Write(Success(filepath.Replace("\\", "\\\\")));
protected string Success(string filepath)
{
return "{\"statusCode\":\"200\", \"message\":\"操作成功!\", \"filepath\":\"" + filepath + "\"}";
}