Aps.net中基于bootstrapt图片上传插件的应用

Aps.net中基于bootstrapt图片上传插件的应用


在最近的项目中需要使用一个图片上传的功能,而且是多张图片同时上传到服务器的文件夹中,将图片路径存放在数据库中。为了外观好看使用了bootstrapt插件。插件下载地址:   http://www.jq22.com/jquery-info5231

 

index.html中的代码:

 

<script>
  //初始化函数
    $("#file-1").fileinput({
        uploadUrl: 'image/Handler.ashx', // you must set a valid URL here else you will get an error
        allowedFileExtensions : ['jpg', 'png','gif'],
        overwriteInitial: false,
        maxFileSize: 1000,
        maxFilesNum: 10,
        //allowedFileTypes: ['image', 'video', 'flash'],
        slugCallback: function(filename) {
            return filename.replace('(', '_').replace(']', '_');
        }
    });
   
    </script>

很多博友在uploadUrl的参数设置中总是表达不清除,使用什么MVC接受图片的信息,现在MVC使用已经下降,我使用一般处理程序完成了图片得保存。

  public class Handler : IHttpHandler
    {
        MethodUpload md = new MethodUpload();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Charset = "utf-8";
            // context.Response.Write(md.SaveFile(context));
            addFile();
        }
        /// <summary>
        /// 添加图片的方法
        /// </summary>
        public void addFile()
        {
            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 != "")
                    {
                        fileExtension = System.IO.Path.GetExtension(fileName);
                        string path = System.Web.HttpContext.Current.Request.MapPath("images/");
                                            
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        postedFile.SaveAs(path + fileName);                      
                    }
                }                        
            }
            catch (System.Exception Ex)
            {
              
            }
        }



        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值