uploadify图片上传插件使用实例
2023-09-27 14:28:17 时间
1、uploadify插件库引用
script src="../js/uploadify/swfobject.js" type="text/javascript" /script script src="../js/uploadify/jquery.uploadify.v2.1.4.js" type="text/javascript" /script
2、uploadify应用代码
$(#uploadify).uploadify({ uploader: ../js/uploadify/uploadify.swf, //指定上传控件的主体文件 script: Handler/UpAdImg.ashx, //指定服务器端上传处理文件 scriptData: { uptype: Upload, option: GoodsImgUpdate }, cancelImg: ../js/uploadify/cancel.png, //指定取消上传的图片 auto: true, //选定文件后是否自动上传 fileExt: *.jpg;*.gif;*.png;*.pdf;*.rar;*.zip;*.exe;*.xls;*.xlsx;*.ppt;*.pptx;*.doc;*.docx;, //控制可上传文件的扩展名,启用本项时需同时声明filedesc fileDesc: 图片格式(*.jpg;*.gif;*.png;*.pdf;*.rar;*.zip;*.exe;), //出现在上传对话框中的文件类型描述 buttonText: 上传图片, //浏览按钮的文本 sizelimit: 824288000, //控制上传文件的大小,单位byte multi: true, //是否允许同时上传多文件 onComplete: function (event, queueId, fileObj, response, data) { var resultJson = eval("(" + response + ")"); if (resultJson.success == true) { var li = $(" li " + " input name=\"hd_upimgId\" type=\"hidden\" value=\"0\" / input name=\"hd_FileName\" type=\"hidden\" value=\"" + resultJson.src + "\" / input name=\"HD_ImageType\" type=\"hidden\" id=\"HD_ImageType\" value=/ " + " div "jPic\" span img src=\"" + resultJson.url + "\" width=160 height=160 / /span i "webNo\" /i /div " + " div "jwz\" div "w1\" 名称: input name=\"txtTitle\" "jbox\" type=\"text\" value=" + resultJson.title + "/ /div div "w1\" 说明: input name=\"txtRemark\" "jbox\" id=\"txtRemark\" type=\"text\"/ /div div "jBtn\" i "fx\" input type=\"checkbox\" / /i a "prev\" href=\"javascript:void(0);\" img src=../images/inc/left.png border=0 / /a a "del\" href=\"javascript:void(0);\" img src=../images/inc/del.png border=0 / /a a "next\" href=\"javascript:void(0);\" img src=../images/inc/right.png border=0 "next\"/ /a /div /div " + " /li3、file控件代码
td input id="uploadify" name="uploadify" type="file" / /td
4、一般处理文件
public void ProcessRequest(HttpContext context) context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; var HttpFile = context.Request.Files["Filedata"]; if (HttpFile != null) var allowedExt = new List string { ".jpg", ".gif", ".bmp", ".png" }; var fileExt = Path.GetExtension(HttpFile.FileName).ToLower(); var File_Name = Path.GetFileNameWithoutExtension(HttpFile.FileName); var uptype = context.Request["uptype"]; var option = context.Request["option"]; if (uptype.ToString().Trim().Equals("Upload")) var toFileName = Guid.NewGuid().ToString() + fileExt; var toFileFullPath = RouteHelp.GoodsSavePath + "\\"; var viewPath = RouteHelp.GoodsImgUrl + "\\"; var Title = File_Name; DirectoryInfo di = new DirectoryInfo(toFileFullPath); if (!di.Exists) di.Create(); string saveFile = toFileFullPath + "D" + toFileName; HttpFile.SaveAs(saveFile); //大缩略图 string bigThumbPath = toFileFullPath + "X" + toFileName; MakeThumbnail(saveFile, bigThumbPath, 430, 430, "Cut "); //小缩略图 string smallThumbPath = toFileFullPath + toFileName; MakeThumbnail(saveFile, smallThumbPath, 177, 177, "Cut "); string imgeUrl = ""; if (fileExt.ToLower().Equals(".jpg") || fileExt.ToLower().Equals(".gif") || fileExt.ToLower().Equals(".bmp") || fileExt.ToLower().Equals(".png")) imgeUrl = viewPath + toFileName; else context.Response.Write("{success:false,msg:只能上传图片类型的文件}"); context.Response.End(); return; AddImgToCookie(toFileName, toFileName, Title, option); context.Response.Write("{success:true,url:" + RouteHelp.GoodsImgUrl + "/" + toFileName + ",src:" + toFileName + ",title:" + Title + "}"); else context.Response.Write("{success:false}"); else context.Response.Write("{success:false}"); }