图片上传uploadify

来源:互联网 发布:哈尔滨大麦网络 编辑:程序博客网 时间:2024/06/05 15:28

图片上传借用js Uploadify,支持多张图片上传

1、下载Uploadify.js  地址http://www.uploadify.com/download/

2、前台页面

<span id="uploadify">上传多张图片</span>
    <script src="~/uploadfy/jquery-2.2.0.min.js"></script>
    <script src="~/uploadfy/uploadify.min.js"></script>
    <script type="text/javascript">
        $('#uploadify').uploadify({
            uploader: '../../Index/Upload',           // 服务器端处理地址
            swf: '../../uploadfy/uploadify.swf',    // 上传使用的 Flash

            width: 60,                          // 按钮的宽度
            height: 23,                         // 按钮的高度
            buttonText: "上传",                 // 按钮上的文字
            buttonCursor: 'hand',                // 按钮的鼠标图标

            fileObjName: 'Filedata',            // 上传参数名称

            // 两个配套使用
            fileTypeExts: "*.jpg;*.png",             // 扩展名
            fileTypeDesc: "请选择 jpg png 文件",     // 文件说明

            auto: true,                // 选择之后,自动开始上传
            multi: true,               // 是否支持同时上传多个文件
            queueSizeLimit: 5          // 允许多文件上传的时候,同时上传文件的个数
        });
    </script> 
3、后台接受、存储

   public ActionResult Upload(HttpPostedFileBase Filedata)
        {
            // 如果没有上传文件
            if (Filedata == null ||
                string.IsNullOrEmpty(Filedata.FileName) ||
                Filedata.ContentLength == 0)
            {
                return this.HttpNotFound();
            }

            // 保存到 ~/photos 文件夹中,名称不变
            string filename = System.IO.Path.GetFileName(Filedata.FileName);
            string upPath = AppDomain.CurrentDomain.BaseDirectory + "Upload/";
            string virtualPath =
                string.Format("~/Images/{0}", filename);
            string path = Path.Combine(upPath, filename);
            Filedata.SaveAs(path);
            return this.Json(new { });
        }
4、具体参数 
查询地址:http://www.uploadify.com/documentation/

0 0
原创粉丝点击