api.ajax({
url : GetWebOrgUrl() + '/AppInfo/UploadHandler.ashx’,
method : 'post',
dataType : 'json',
returnAll : false,
report : true,
data : {
files : {
"pic" : data
}
}
}, function(ret, err) {
if (ret) {
//上传中
if (ret.status == 0) {
if (ret.progress == 100) {
ProgressBar(ret.progress);
}
}
//上传完成
if (ret.status == 1) {
if (ret.body.msg.indexOf("成功") > -1) {
if (isEmpty(ret.body.path)) {
api.toast({
msg : '上传成功',
location : 'middle'
});
//关闭模块
UIActionProgress.close();
//回调图片
UploadingCallback(ret.body.path);
} else {
api.toast({
msg : '上传失败',
location : 'middle'
});
}
}
api.hideProgress();
}
} else {
api.alert({
msg : ('错误信息:' + err.msg + ';网络状态:' + err.statusCode),
location : 'middle'
});
api.hideProgress();
}
});
#region 上传图片处理
if (context.Request.Files["pic"] != null)
{
string path = context.Request.Files["pic"].ToString();
string[] array = path.Split(',');
HttpPostedFile file = context.Request.Files["pic"];
if (file.ContentLength <= maxFileSize)
{
//上传路径
if (System.IO.Directory.Exists(context.Server.MapPath(_urlpath)) == false)
{
System.IO.Directory.CreateDirectory(context.Server.MapPath(_urlpath));//不存在,创建文件夹
}
if (context.Request.Files.Count > 0)
{
for (int i = 0; i < context.Request.Files.Count; i++)
{
string fileName = file.FileName;//获取文件名(有些浏览器取到带路径的文件名)
fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);//获取文件名(带后缀名),去掉了前面的路径
fileName = fileName.Replace("#", "").Replace("@", "").Replace("%", "").Replace("&", "");//去掉图片名称中导致图片无法查看的特殊符号
if (System.IO.Directory.Exists(context.Server.MapPath(_urlpath)) == false)
{//判断该文件夹是否存在
System.IO.Directory.CreateDirectory(context.Server.MapPath(_urlpath));//不存在,创建文件夹
}
string newFileName = DateTime.Now.Ticks.ToString() + "_" + fileName;//新的文件名
string serverSavePath = _urlpath + newFileName;//得到服务器保存的路径
string fileAbsPath = context.Server.MapPath(serverSavePath);//绝对路径
file.SaveAs(fileAbsPath);
ret = "{\"status\": 200, \"msg\": \"上传文件成功!\", \"path\": \"" + serverSavePath + "\"}";
context.Response.Write(ret);
}
}
}
#endregion