Uploadify flash 上传

下载需要的文件 http://www.uploadify.com/download/ ,千万别忘了 jquery 文件

html:

<html><head runat="server">

    <title></title>
    <link href="js/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="js/uploadify/jquery.uploadify-3.1.js" type="text/javascript"></script> <!-- uploadify某.某版本js-->
 <script type="text/javascript">
        $(function () {
            $("#uploadify").uploadify({
                //指定swf文件
                'swf': 'js/uploadify/uploadify.swf',
                //后台处理的页面
                'uploader': 'UploadHandler.ashx',
                //按钮显示的文字
                'buttonText': '上传图片',
                //显示的高度和宽度,默认 height 30;width 120
                //'height': 15,
                //'width': 80,
                //上传文件的类型  默认为所有文件    'All Files'  ;  '*.*'
                //在浏览窗口底部的文件类型下拉菜单中显示的文本
                'fileTypeDesc': 'Image Files',
                //允许上传的文件后缀
                'fileTypeExts': '*.gif; *.jpg; *.png',
                //发送给后台的其他参数通过formData指定
                //'formData': { 'someKey': 'someValue', 'someOtherKey': 1 },
                //上传文件页面中,你想要用来作为文件队列的元素的id, 默认为false  自动生成,  不带#
                //'queueID': 'fileQueue',
                //选择文件后自动上传
                'auto': true,
                //设置为true将允许多文件上传
                'multi': true
            });
        });
    
    </script>
</head>
<body>
    <div>
        <%--用来作为文件队列区域--%>
        <div id="fileQueue">
        </div>
        <input type="file" name="uploadify" id="uploadify" />
        <p>
            <a href="javascript:$('#uploadify').uploadify('upload')">上传</a>| 
            <a href="javascript:$('#uploadify').uploadify('cancel')">取消上传</a>
        </p>
    </div>
</body>

</html>


一般处理程序:

public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //http://www.cnblogs.com/babycool/
            //接收上传后的文件
            HttpPostedFile file = context.Request.Files["Filedata"];
            //其他参数
            //string somekey = context.Request["someKey"];
            //string other = context.Request["someOtherKey"];
            //获取文件的保存路径
            string uploadPath =
                HttpContext.Current.Server.MapPath("UploadImages" + "\\");
            //判断上传的文件是否为空
            if (file != null)
            {
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                //保存文件
                file.SaveAs(uploadPath + file.FileName);
               context.Response.Write("1");
            }
            else
            {
                context.Response.Write("0");
            }  


        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }



假如你上传的文件太大,在一般处理程序会报错。上传文件超时,需要在web.config文件中加入

主要设置:
<httpRuntime executionTimeout="90" maxRequestLength="800000" />

全部设置:
<httpRuntime 
            executionTimeout="90"
            maxRequestLength="4096"
            useFullyQualifiedRedirectUrl="false"
            minFreeThreads="8"
            minLocalRequestFreeThreads="4"
            appRequestQueueLimit="100"
            enableVersionHeader="true"
        />
这样之后就可以搞定了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Jquery Uploadify 是一个基于 Jquery 的文件上传插件,它使用 Flash 技术来实现文件上传功能。它简单易用,可以方便地进行文件上传,并提供了多个自定义选项,如文件大小限制、文件类型限制等。 H5 上传指的是使用 HTML5 中的 File API 来实现文件上传功能。与传统的 Flash、Java Applet 等方式相比,H5 上传更加安全、快速,并且不需要额外安装插件。 使用 Jquery Uploadify 进行 H5 上传,可以通过以下步骤进行操作: 1. 下载并引入 Jquery Uploadify 插件文件,并确保引入了 jQuery 库。 2. 在 HTML 文件中创建一个显示上传文件区域的容器,如: <div id="file-upload-container"> <input type="file" id="file-upload" name="file-upload" multiple> </div> 3. 在 JavaScript 文件中,使用 Jquery 的选择器选取文件上传区域,然后调用 Uploadify 插件的方法进行初始化,如: $("#file-upload").uploadify({ swf: 'uploadify.swf', // 指定 Flash 文件路径 uploader: 'uploadify.php', // 指定上传文件的服务器端处理文件路径 // 其他自定义选项... }); 4. 在服务器端编写处理文件上传的脚本(uploadify.php)。可以使用 PHP、Java、Python 等服务器端语言进行处理,并根据上传结果返回相应的提示信息。 通过以上步骤,我们就可以使用 Jquery Uploadify 插件进行 H5 文件上传了。需要注意的是,由于 H5 上传只能在现代浏览器中完全支持,所以在使用时应该检查浏览器兼容性,确保用户能够正常上传文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值