62,074
社区成员
发帖
与我相关
我的任务
分享
function ajaxFileUpload() {
$.ajaxFileUpload
(
{
url: '/ajax/upload',
secureuri: false,
fileElementId: 'upload_img',
dataType: 'json',
data: { name: 'logan', id: 'id' },
success: function (data, status) {
alert("成功"); //这个地方无法获得data的结果。。。 if (typeof (data.error) != 'undefined') {
if (data.error != '') {
alert(data.error);
} else {
alert(data.msg);
}
}
},
error: function (data, status, e) {
alert(e);
}
}
)
return false;
}
[HttpPost]
public string UpLoad()
{
HttpFileCollectionBase files = HttpContext.Request.Files;
string imgName = string.Empty;
if (files.Count > 0)
{
try
{
string fileDirectory = DateTime.Now.ToString("yyyyMM");
Tools.Download.CreateDirectory();
imgName = Tools.Download.CreateImgName();
for (int i = 0; i < files.Count; i++)
{
if (files[i].FileName != "")
{
string imgStyle = files[i].ContentType;
if (imgStyle.StartsWith("image/bmp") || imgStyle.StartsWith("image/gif") || imgStyle.StartsWith("image/pjpeg") || imgStyle.StartsWith("image/jpeg") || imgStyle.StartsWith("image/x-png"))
{
string savePath = HttpContext.Server.MapPath("/d/m/") + fileDirectory + "/" + imgName;
files[i].SaveAs(savePath);
new Ny.Function.Utility.HelperImg().MakeImg("/d/m/" + fileDirectory + "/" + imgName, "/d/228/" + fileDirectory + "/", 228, 390, 95, 1);
new Ny.Function.Utility.HelperImg().MakeImg("/d/m/" + fileDirectory + "/" + imgName, "/d/100/" + fileDirectory + "/", 100, 100, 100, 175, 95, 1);
new Ny.Function.Utility.HelperImg().MakeImg("/d/m/" + fileDirectory + "/" + imgName, "/d/56/" + fileDirectory + "/", 56, 56, 56, 86, 95, 1);
return imgName;
}
}
}
}
catch (Exception)
{
return "成功";
}
}
return imgName;
}
if (files.Count > 0)
{
try
{
string fileDirectory = DateTime.Now.ToString("yyyyMM");
Tools.Download.CreateDirectory();
imgName = Tools.Download.CreateImgName();
for (int i = 0; i < files.Count; i++)
{
if (files[i].FileName != "")
{
string imgStyle = files[i].ContentType;
if (imgStyle.StartsWith("image/bmp") || imgStyle.StartsWith("image/gif") || imgStyle.StartsWith("image/pjpeg") || imgStyle.StartsWith("image/jpeg") || imgStyle.StartsWith("image/x-png"))
{
string savePath = HttpContext.Server.MapPath("/d/m/") + fileDirectory + "/" + imgName;
files[i].SaveAs(savePath);
new Ny.Function.Utility.HelperImg().MakeImg("/d/m/" + fileDirectory + "/" + imgName, "/d/228/" + fileDirectory + "/", 228, 390, 95, 1);
new Ny.Function.Utility.HelperImg().MakeImg("/d/m/" + fileDirectory + "/" + imgName, "/d/100/" + fileDirectory + "/", 100, 100, 100, 175, 95, 1);
new Ny.Function.Utility.HelperImg().MakeImg("/d/m/" + fileDirectory + "/" + imgName, "/d/56/" + fileDirectory + "/", 56, 56, 56, 86, 95, 1);
return "{'error':'','msg':'upload successfully'}";
}
}
}
}
catch (Exception ex)
{
return "{'error':'error','msg':'"+ex.Message+"'}";
}
}
return "{'error':'error','msg':'empty file'}";
还有看ajax返回的内容可以用firebug检查比较方便