博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Sencha Toucha 2.1 文件上传
阅读量:7101 次
发布时间:2019-06-28

本文共 2685 字,大约阅读时间需要 8 分钟。

 javascript代码:

Ext.onReady(function() {                Ext.create('Ext.form.Panel',                {                title: 'Upload a Photo',                width: 400,                bodyPadding: 10,                frame: true,                renderTo: "div1",                items: [{                    xtype: 'filefield',                    name: 'photo',                    fieldLabel: 'Photo',                    labelWidth: 50,                    msgTarget: 'side',                    allowBlank: false,                    anchor: '100%',                    buttonText: 'Select Photo...'}],                    buttons: [{ text: 'Upload',                        handler: function() {                            var form = this.up('form').getForm();                            if (form.isValid()) {                                form.submit({ url: 'RemoteFileUpload.aspx',                                    waitMsg: 'Uploading your photo...',                                    success: function(fp, o) {                                        Ext.Msg.alert('Success', 'Your photo "' + o.result.file + '" has been uploaded.');                                    }                                });                            }                        }                }]            });        });
后台代码:

protected void Page_Load(object sender, EventArgs e)        {            Response.Clear();            if (this.SaveFiles())            {                Response.Write("{success:true,msg:'File was successfully uploaded.'}");            }            else            {                Response.Write("{success:true,msg:'Possible file upload attack!'}");            }            Response.End();        }        public Boolean SaveFiles()        {            ///遍历File表单元素                  HttpFileCollection files = HttpContext.Current.Request.Files;            try            {                for (int iFile = 0; iFile < files.Count; iFile++)                {                               ///检查文件扩展名字                                  HttpPostedFile postedFile = files[iFile];                    string fileName, fileExtension;                    fileName = System.IO.Path.GetFileName(postedFile.FileName);                    if (fileName != "")                    {                        ///注意:可能要修改你的文件夹的匿名写入权限。                                   postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("upload_files/") + fileName);                    }                }                 return true;            }            catch (System.Exception Ex)            {                 return false;             }        }

转载于:https://www.cnblogs.com/fyq891014/p/3294744.html

你可能感兴趣的文章
网页浏览器知道我们的哪些信息?(2)
查看>>
CSS不常用属性---Tips1文本样式
查看>>
深入 Flask 源码理解 Context
查看>>
js原型和继承
查看>>
在Github上部署Ghost
查看>>
Android Studio 快捷键 for Mac OS X
查看>>
[分享]你写过 Web 爬虫, 那么你写过 P2P 爬虫吗?
查看>>
Session原理
查看>>
[Leetcode] Rotate Image 旋转图片
查看>>
GOAndroid的安装和配置
查看>>
JavaScript 内存机制(前端同学进阶必备)
查看>>
javascript dom的图片最终版源代码 (重复看)
查看>>
innobackupex在线备份及恢复(全量和增量)
查看>>
spring-AspectJ最终通知
查看>>
中国电信涉足VR,以“情景式VR消费计划”带来商业变现
查看>>
逃离智能家居“怪圈”,智能音箱并不是唯一入口
查看>>
Linux 格式化扩展分区(Extended)
查看>>
MySQL 安装步骤详解
查看>>
AR VR或将彻底变革广告营销行业
查看>>
dell r710 装系统
查看>>