uploadify上传控件

下载控件:uploadify 分为2种,选择Flash Version版本

地址:http://www.uploadify.com/ 

页面代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Upload.aspx.cs" Inherits="Hot.Upload" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="Scripts/upload/uploadify.css" rel="stylesheet" />
    <script src="Scripts/jquery-1.7.1.min.js"></script>
    <script src="Scripts/upload/jquery.uploadify.min.js"></script>
    <title>上传控件</title>
    
    <script type="text/javascript">
        $(document).ready(function () {
            $("#uploadify").uploadify({
                'swf': 'Scripts/upload/uploadify.swf',
                'uploader': '/UploadHandler.ashx',
                'cancelImg': 'Scripts/upload/uploadify-cancel.png',
                'queueID': 'fileQueue',
                'uploadLimit': 1000,        //一次浏览器课上成总数量
                //'fileSizeLimit': '100MB',   //单个文件大小设置
                'auto': false,
                'multi': true,
                'onFallback':function(){  
                   alert("您未安装FLASH控件,无法上传图片!请安装FLASH控件后再试。");  
                },  
                //返回一个错误,选择文件的时候触发  
                'onSelectError': function (file, errorCode, errorMsg) {
                    switch (errorCode) {
                        case -100:
                            alert("上传的文件数量已经超出系统限制的" + $('#file_upload').uploadify('settings', 'queueSizeLimit') + "个文件!");
                            break;
                        case -110:
                            alert("文件 [" + file.name + "] 大小超出系统限制的" + $('#file_upload').uploadify('settings', 'fileSizeLimit') + "大小!");
                            break;
                        case -120:
                            alert("文件 [" + file.name + "] 大小异常!");
                            break;
                        case -130:
                            alert("文件 [" + file.name + "] 类型不正确!");
                            break;
                    }
                    alert(errorCode);
                },
                'onUploadStart': function (file) {
                },
                'onUploadSuccess': function (file, data, response) {
                    $('#' + file.id).find('.data').html(' 上传完毕');
                },
                'onUploadComplete': function () {
                     
                }

            });
        });
    </script>

</head>
<body>
    
      <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>

   
</body>
</html>

上传到后台:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace Hot
{
    /// <summary>
    /// UploadHandler 的摘要说明
    /// </summary>
    public class UploadHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
           
            //接收上传后的文件
            HttpPostedFile file = context.Request.Files["Filedata"];
            //其他参数
            //string somekey = context.Request["someKey"];
            //string other = context.Request["someOtherKey"];
            //获取文件的保存路径 创建uploads文件夹
            string uploadPath =HttpContext.Current.Server.MapPath("uploads" + "\\");
            //判断上传的文件是否为空
            if (file != null)
            {
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                //1.利用InputStream 属性直接从HttpPostedFile对象读取文本内容
                System.IO.Stream MyStream;
                int FileLen;
                FileLen = file.ContentLength;
                // 读取文件的 byte[] 
                byte[] bytes = new byte[FileLen];
                MyStream = file.InputStream;
                MyStream.Read(bytes, 0, FileLen);

                //2.保存到文件
                file.SaveAs(uploadPath + file.FileName);
                context.Response.Write("1");
            }
            else
            {
                context.Response.Write("0");
            }  

        }

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


1.记得创建uploads文件夹,放上传的文件。

 2.$('#' + file.id).find('.data').html(' 上传完毕'); 是设置显示为中文完成,不然是英文,也可以更改jquery.uploadify.js文件里的英文字。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

低调之人

略表心意,哈哈哈

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值