uploadify控件实例,浏览以及中文按钮问题

 前台代码:<script type="text/javascript">
        $(document).ready(function()
        {
       
       
            $("#uploadify").uploadify({
                'uploader': '../../js/jquery.uploadify-v2.1.0/uploadify.swf',
                'script': '../../UploadHandler.ashx',
                'scriptData': {'filepath':'<%= filepath %>'},
                'cancelImg': '../../js/jquery.uploadify-v2.1.0/cancel.png',
                //'folder': '../../pic/'+<%= filepath %>,
                'folder': '../../pic',
                'queueID': 'fileQueue',
                'auto': false,
                'multi': false,
                //'buttonImg':'../../pic/shangchuan.jpg',
               'width':'90',//设置按钮离的左边距
//                'height':'80',//设置按钮离的上边距
                'fileExt': '*.gif;*.jpg;*.jpeg;*.png;*.bmp',
                'fileDesc': 'Image Files',
                'method': 'GET',
                'wmode':'transparent',
                'buttonText':'浏览图片',
    
                //'rollover':true
            'onComplete':function(event,queueId,fileObj,response,data){
   
     $('#filerigth').append('<img src="../../pic/'+response+'" alt="首饰"  height="250" width="300">');
        
            $('#Button1').hide();
            $('#Label1').hide();
            $('#Label2').hide();
            }
            
           });
        }); 

 

 

后台UploadHandler.ashx

 

public class UploadHandler : IHttpHandler {

       public readonly string connectionString = Crab_DBUtility.SqlHelper.LocalSqlServer;
        protected string imagePath;//图片路径
        protected string imageType;//图片类型
        protected string imageName;//图片名称
        protected string fileName;//图片名称
        //提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行
         //如果此方法确定 GetThumbnailImage 方法应提前停止执行,则返回 true;否则返回 false
             public void ProcessRequest(HttpContext context)
        {
             context.Response.ContentType = "text/plain";
             HttpPostedFile UploadImage = context.Request.Files["FileData"];
             string filepath = context.Request.Params["filepath"];
             //物理路径
             string uploadpath = HttpContext.Current.Server.MapPath(context.Request["folder"] + "\\");
 
             if (UploadImage != null)
             {
                                  string filename = UploadImage.FileName;
                                 fileName = filepath + ".png";
             
           
             }
           else
             {
                context.Response.Write("0");
             }

            string mPath;
           //取得图片名称
            imagePath = UploadImage.FileName;
           //取得图片类型
            imageType = imagePath.Substring(imagePath.LastIndexOf(".") + 1);
            imageName = imagePath.Substring(imagePath.LastIndexOf("\\") + 1);
            Stream imgStream = UploadImage.InputStream;//流文件,准备读取上载文件的内容
            int imgLen = UploadImage.ContentLength;//上载文件大小
            //建立虚拟路径
            mPath = HttpContext.Current.Server.MapPath(context.Request["folder"]);
            //保存到虚拟路径
            UploadImage.SaveAs(mPath + "\\" + fileName);
                      context.Response.Write(fileName);
      

       }

 

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

}

 

 

 

另外使用中文按钮的问题请参考carekee的博文
http://www.cnblogs.com/carekee/archive/2011/11/02/2233288.html

使用buttonImg是有来设置图片按钮,显示按钮的过程会很慢,不推荐

直接下载博主提供的

修复中文按钮乱码的jQuery uploadify (361)

覆盖即可,感谢博主。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值