EXT.NET MVC5 工作随笔08 关于前台上传多个图片和单个图片的写法
来源:互联网 发布:cp1200写频软件下载 编辑:程序博客网 时间:2024/06/01 10:40
后前代码:
public ActionResult UploadClick(string P_Name, string tName, string ID)//参数为路径 文件全名含格式 要保存到该条数据的ID { DirectResult result = new DirectResult(); if (P_Name != "" && tName != "" && ID != "") { string tpl = "Uploaded file: {0}<br/>Size: {1} bytes"; if (this.GetCmp<FileUploadField>("FileUploadField1").HasFile) { X.Msg.Show(new MessageBoxConfig { Buttons = MessageBox.Button.OK, Icon = MessageBox.Icon.INFO, Title = "Success", Message = string.Format(tpl, this.GetCmp<FileUploadField>("FileUploadField1").PostedFile.FileName, this.GetCmp<FileUploadField>("FileUploadField1").PostedFile.ContentLength) }); HttpContextBase context = this.HttpContext; try { HttpPostedFileBase file; string filePath = "~/UploadPhoto/" + P_Name + "/"; if (Directory.Exists(Server.MapPath(filePath))) { for (int i = 0; i < context.Request.Files.Count; ++i) { file = context.Request.Files[i]; if (file == null || file.ContentLength == 0 || string.IsNullOrEmpty(file.FileName)) continue; string fileFullName = Server.MapPath(filePath + file.FileName); file.SaveAs(fileFullName); context.Response.Write("1"); context.Response.Flush(); } } else { Directory.CreateDirectory(Server.MapPath(filePath)); for (int i = 0; i < context.Request.Files.Count; ++i) { file = context.Request.Files[i]; if (file == null || file.ContentLength == 0 || string.IsNullOrEmpty(file.FileName)) continue; string fileFullName = Server.MapPath(filePath + file.FileName); file.SaveAs(fileFullName); context.Response.Write("1"); context.Response.Flush(); } } } catch (Exception ex) { ReturnMsg.MsgCode = "9999"; ReturnMsg.Msg = string.Format("系统错误:{0}", ex); context.Response.End(); } finally { context.Response.End(); } } else { X.Msg.Show(new MessageBoxConfig { Buttons = MessageBox.Button.OK, Icon = MessageBox.Icon.ERROR, Title = "Fail", Message = "No file uploaded" }); } string URL = "\\UploadPhoto\\" + P_Name + "\\" + tName; int iCount = BLL_DO_STAMP_FIGURE.Init.InsertURL(ID, URL);//保存进库到表,根据ID if (iCount > 0) { result.IsUpload = true; } } return result; }多张上传时:
JS判断:
//上传图片判断 var loadFailed = function () { X.Msg.show({ title: "操作提示", icon: X.MessageBox.ERROR, msg: "文件加载发生错误,请联系维护人员进行解决!", buttons: X.Msg.OK }); }; //上传图片判断 var fileSelected = function (item, file) { if (file.name == 'image.jpg') { X.Msg.show({ title: "操作提示", icon: X.MessageBox.ERROR, msg: '不能上传名称为"image.jpg"的文件,请修改!', buttons: X.Msg.OK }); return false; } //var TempFileValue = file.name.split(" "); //if (TempFileValue[2].indexOf("×") < 0) { // X.Msg.show({ title: "操作提示", icon: X.MessageBox.INFO, msg: '上传图片名称不规范!', buttons: X.Msg.OK }); // return false; //} //else { // var TempZPLXValue = TempFileValue[2].split("×"); //} //if (TempZPLXValue[1].indexOf(".") < 0) { //} //else { // var TempZPFDBSValue = TempZPLXValue[1].split("."); //} //this.up('grid').store.add({ // YSYH: App.GP_Main.getSelectionModel().getSelection()[0].data.YSYH, // YPBH: App.GP_Main.getSelectionModel().getSelection()[0].data.YPBH, // BDZPM: file.name, // ZPBH: TempFileValue[0], // ZPLRMS: TempFileValue[1], // ZPFDBS: TempZPFDBSValue[0] //}); //App.B_Detail_Upload.enable(); }; //上传图片判断 var fileSelectionError = function (item, file, errorCode, message) { if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) { alert("所选文件过多.\n" + (message === 0 ? "单次上传文件个数不得多于100个." : "你可以选择 " + (message > 1 ? "up to " + message + " files." : "一个文件."))); return; } switch (errorCode) { case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT: alert("错误: 大小超出15M, 文件: " + file.name + ", 文件大小: " + file.size + ", 错误信息: " + message); break; case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE: alert("错误: 内容为空,不能进行上传, 文件: " + file.name + ", 文件大小: " + file.size + ", 错误信息: " + message); break; case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE: alert("错误: 无效的文件类型, 文件: " + file.name + ", 文件大小: " + file.size + ", 错误信息: " + message); break; default: alert("错误: " + errorCode + ", 文件: " + file.name + ", 文件大小: " + file.size + ", Message: " + message); break; } }; //上传图片判断 var uploadError = function (item, file, errorCode, message) { switch (errorCode) { case SWFUpload.UPLOAD_ERROR.HTTP_ERROR: alert("错误: HTTP 错误, 文件: " + file.name + ", 错误信息: " + message); break; case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED: alert("错误: 上传 错误, 文件: " + file.name + ", 文件大小: " + file.size + ", 错误信息: " + message); break; case SWFUpload.UPLOAD_ERROR.IO_ERROR: alert("错误: IO 错误, 文件: " + file.name + ", 错误信息: " + message); break; case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR: alert("错误: 安全错误, 文件: " + file.name + ", 错误信息: " + message); break; case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED: alert("错误: 文件超过大小限制, 文件: " + file.name + ", 文件大小: " + file.size + ", 错误信息: " + message); break; case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED: alert("错误: 文件验证失败, 文件: " + file.name + ", 文件大小: " + file.size + ", 错误信息: " + message); break; default: alert("错误: " + errorCode + ", 文件: " + file.name + ", 文件大小: " + file.size + ", 错误信息: " + message); break; } }; //上传图片判断 var GetUploadResault = function (file, data, response) { if (response != "1") { X.Msg.show({ title: "操作提示", icon: X.MessageBox.ERROR, msg: "文件上传发生错误,请联系维护人员进行解决!", buttons: X.Msg.OK }); } };
<span style="background-color: rgb(240, 240, 240);"> X.FormPanel().ID("FP_1").Region(Region.Center).Layout(LayoutType.Card).Border(true).Flex(1).Split(true)</span> .TopBar(X.Toolbar() .Items( X.FileUploadField().ID("FUF_Photo").Width(400).Icon(Icon.Attach).ButtonText("浏览文件"),
X.TextField().ID("PhotoName"), X.MultiUpload().ID("MU_Detail").FileDropAnywhere(true).FileSizeLimit("15MB").FileTypes("*.jpg;*.jpeg;*.bmp;") .FileTypesDescription("所有文件") .FileUploadLimit(100).FileQueueLimit(0).UploadUrl(Url.Action("ProcessRequest")) .PostParams(d => { d.Add(new Parameter("P_Name", "App.GP_Well.getSelectionModel().getSelection()[0].data.STAMP_FIGURE_NAME", ParameterMode.Raw)); }) .Listeners(ls => ls.SwfUploadLoadFailed.Fn = "loadFailed") .Listeners(ls => ls.FileSelected.Fn = "fileSelected") .Listeners(ls => ls.FileSelectionError.Fn = "fileSelectionError") .Listeners(ls => ls.UploadError.Fn = "uploadError") .Listeners(ls => ls.UploadSuccess.Fn = "GetUploadResault"),后台:
HttpContextBase context = this.HttpContext; try { HttpPostedFileBase file; string filePath = "~/UploadPhoto/" + P_Name + "/"; if (Directory.Exists(Server.MapPath(filePath))) { for (int i = 0; i < context.Request.Files.Count; ++i) { file = context.Request.Files[i]; if (file == null || file.ContentLength == 0 || string.IsNullOrEmpty(file.FileName)) continue; string fileFullName = Server.MapPath(filePath + file.FileName); file.SaveAs(fileFullName); context.Response.Write("1"); context.Response.Flush(); } } else { Directory.CreateDirectory(Server.MapPath(filePath)); for (int i = 0; i < context.Request.Files.Count; ++i) { file = context.Request.Files[i]; if (file == null || file.ContentLength == 0 || string.IsNullOrEmpty(file.FileName)) continue; string fileFullName = Server.MapPath(filePath + file.FileName); file.SaveAs(fileFullName); context.Response.Write("1"); context.Response.Flush(); } } } catch (Exception ex) { ReturnMsg.MsgCode = "9999"; ReturnMsg.Msg = string.Format("系统错误:{0}", ex); context.Response.End(); } finally { context.Response.End(); } }
0 0
- EXT.NET MVC5 工作随笔08 关于前台上传多个图片和单个图片的写法
- EXT.NET MVC5 工作随笔06 保存前提示框 及formpanel 的有效性判断
- asp.net(C#)上传单个图片并判断图片的类型和大小(源代码)vs2008
- asp.net(C#)上传单个图片并判断图片的类型和大小(源代码)
- springmvc_mybatis中关于图片上传的写法
- ext.net图片上传代码
- EasyUI file-box+SpringMVC 单个或多个图片上传
- 前台显示上传的图片
- 关于多张图片和单个图片的背景选择的问题
- 图片预览,单个/多个图片预览
- 控制器接收图片和上传图片写法
- 单个图片上传
- PHP单个图片上传
- EXT.NET应用例子,上传和下载图片及与数据库的交互
- 图片的多个上传
- Asp.Net同时上传多个图片
- ASP.NET同时上传多个图片
- asp.net mvc5 与图片
- centos 同步外网源到本地
- 字符串训练(二)模拟实现strstr strncpm strncat strncpy函数
- OpenStack Glance 之paste
- 让Apache的commons-net-3.3中的FTPClient支持中文
- 规律题_1
- EXT.NET MVC5 工作随笔08 关于前台上传多个图片和单个图片的写法
- hdu 5795 A Simple Nim
- 六度分离
- 浅谈微信卡券功能开发(1)
- vmstat命令的输出解释
- MySQL技术内幕InnoDB存储引擎学习笔记(第六章)
- CUDA编程_DEBUG_01
- 监听activeMQ的状态
- 二叉树前、中、后序遍历【非递归】【LintCode测试平台】