uploadify能够时间文件的批量上传,JS文件包下载地址,使用说明可以参考官网文档(http://www.uploadify.com/documentation/)
使用方法如下代码:
$("#btnfileupload").uploadify({
swf: '/Content/uploadify/uploadify.swf',
cancelImg: '/Content/uploadify/cancel.png',
uploader: '../upload/Uploadfile',
width: ,
buttonText: '批量上传',
fileTypeExts: '*.jpg;*.gif;*.jpeg;*.png;',
formData: { 'filepath': 'ttrs' },
fileObjName: 'upimage',
auto: true,
multi: true,
uploadLimit: ,
successTimeout: ,
removeCompleted: true,
removeTimeout: ,
onUploadSuccess: function (file, data, response) {
$("#mydefault").hide();
data = window.eval('(' + data + ')');//转换成JSON
file.name = data.piccode;
if ($("#" + data.piccode).length == )
jQuery("<li id=\"" + data.piccode + "\"><img src='" + data.picurl + "' /><input type=\"hidden\" name=\"detailpic\" value=\"" + data.piccode + "\"></li>").appendTo("#mypicshowdiv");
}
});
后台MVC4代码如下:
[HttpPost]
public JsonResult UploadImg(HttpPostedFileBase upimage)
{
string pic = "", error = "",pcode="";
try
{
if (upimage != null)
{
string fileName = DateTime.Now.ToString("yyyyMMdd") + System.IO.Path.GetFileName(upimage.FileName);
string[] pictext = { ".jpg",".gif",".bmp",".png",".jpeg" };
string extenname= System.IO.Path.GetExtension(fileName);
if (pictext.Contains(extenname))
{
string filePhysicalPath = Server.MapPath("~/Upload/Images/" + fileName);
upimage.SaveAs(filePhysicalPath);
pic = "/Upload/Images/" + fileName;
}
else
{
error = "";
pic =pic ;
}
}
}
}
catch (Exception ex)
{
error = ex.Message;
}
return Json(new
{
errorcode = error,
picurl = pic,
piccode = pcode
});
}