• jquery上传控件个人使用


    转了一篇jquery的上传控件使用博文,但是,经过测试貌似不行,自己研究了一下,效果实现。记下,以后使用。

    下载“Uploadify”,官方版本为php的,很多文件不需要,删除带.php的文件。

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript" src="js/jquery-1.4.1.min.js"></script>
        <link href="js/uploadify/uploadify.css" type="text/css" rel="Stylesheet"/>
        <script type="text/javascript" src="js/uploadify/jquery.uploadify.js"></script>
        <script type="text/javascript" src="js/uploadify/jquery.uploadify.min.js"></script>
         
        <script type="text/javascript">
            $(function () {
                $("#uploadify").uploadify({

                    'buttonClass': 'button',
                    'height': '20',
                    'width':'30',
                    'swf': './js/uploadify/uploadify.swf',
                    'cancelImg': './js/uploadify/uploadify-cancel.png',
                    'folder': './upload',
                    'buttonText': '上传',
                    'uploader': './UpLoadHandler.ashx',
                    'queueID': 'd',
                    'auto': 'true',
                    'multi': true,
                    'fileTypeDesc': 'Wrod文档(*.doc,*.docx)|Excel文件(*.xls,*.xlsx)|图片文件(*.jpg;*.png;*.gif;*.bmp;*.jpeg;*.tiff;*.dwg)|压缩文件(*.zip;*.rar;*.7z)',
                    'fileTypeExts': '*.doc;*.docx|*.xls,*.xlsx|*.jpg;*.png;*.gif;*.bmp;*.jpeg;*.tiff;*.dwg|*.zip;*.rar;*.7z',

                    'onUploadSuccess': function (file, data, response) {
                        if (data.indexOf('错误提示') > -1) {
                            alert(data);
                        }
                        else {
                           
                            alert("上传成功!");
                        }
                    },
                    'onUploadError': function (file, errorCode, errorMsg, errorString) {
                        alert('文件:' + file.name + ' 上传失败: ' + errorString);
                    }

                });

               
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <div id="d"></div>
        <input type="file" id="uploadify" name="uploadify" />
        </div>
        </form>
    </body>
    </html>

    后台代码:

    在一般处理程序里

    public class UpLoadHandler : IHttpHandler,System.Web.SessionState.IRequiresSessionState{
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            context.Response.Charset = "utf-8";
            string uploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\";
            HttpPostedFile file = context.Request.Files["Filedata"];
            if (file != null)
            {
                if (!System.IO.Directory.Exists(uploadPath))
                {
                    System.IO.Directory.CreateDirectory(uploadPath);
                }
                context.Session["FilePath"] = uploadPath + file.FileName;//将上传文件路径保存到session 用于跨页传递
               
                file.SaveAs(uploadPath + file.FileName);
              
            }
         
            //context.Response.Write("Hello World");
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }

    }

  • 相关阅读:
    Kendo UI for ASP.NET MVC 的一些使用经验
    AI智能技术监控学生上课行为,智慧管理加强校园教学质量
    如何通过ffmpeg 实现实时推流和拉流保存的功能
    如何测试流媒体服务器的并发能力?
    TSINGSEE青犀视频H265播放器FLV.js播放一段时间后报内存不足怎么处理?
    互动电视的未来应该是什么样的?
    牛客练习赛89 题解
    【洛谷P3934】炸脖龙 I
    【CF1463F】Max Correct Set
    【CF1496F】Power Sockets
  • 原文地址:https://www.cnblogs.com/net-study/p/3382587.html
Copyright © 2020-2023  润新知