Asp.Net上传大文件带进度条swfupload

Asp.Net基于swfupload上传大文件带进度条百分比显示,漂亮大气上档次,大文件无压力,先看效果

一、上传效果图

1、上传前界面:图片不喜欢可以自己换

2、上传中界面:百分比显示

 

3、上传后返回文件地址,我测试呢所以乱写的

二、核心代码

upload.htm代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>博客园:webapi</title>
    <link href="css.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="swfupload/swfupload.js"></script>
    <script type="text/javascript" src="js/swfupload.queue.js"></script>
    <script type="text/javascript" src="js/fileprogress.js"></script>
    <script type="text/javascript" src="js/filegroupprogress.js"></script>
    <script type="text/javascript" src="js/handlers.js"></script>
    <script type="text/javascript">
        var swfu;

        window.onload = function () {
            var settings = {
                flash_url: "swfupload/swfupload.swf",
                upload_url: "uploadFile.ashx",
                file_size_limit: "409600",
                file_types: "*.apk;*.ipa",
                file_types_description: "Web Image Files",
                file_size_limit: "307200",
                file_upload_limit: 1,
                file_queue_limit: 1,
                custom_settings: {
                    progressTarget: "divprogresscontainer",
                    progressGroupTarget: "divprogressGroup",

                    //progress object
                    container_css: "progressobj",
                    icoNormal_css: "IcoNormal",
                    icoWaiting_css: "IcoWaiting",
                    icoUpload_css: "IcoUpload",
                    fname_css: "fle ftt",
                    state_div_css: "statebarSmallDiv",
                    state_bar_css: "statebar",
                    percent_css: "ftt",
                    href_delete_css: "ftt",

                    //sum object
                    /*
                    页面中不应出现以"cnt_"开头声明的元素
                    */
                    s_cnt_progress: "cnt_progress",
                    s_cnt_span_text: "fle",
                    s_cnt_progress_statebar: "cnt_progress_statebar",
                    s_cnt_progress_percent: "cnt_progress_percent",
                    s_cnt_progress_uploaded: "cnt_progress_uploaded",
                    s_cnt_progress_size: "cnt_progress_size"
                },
                debug: false,

                // Button settings
                button_image_url: "images/btnupload.png",
                button_width: "301",
                button_height: "171",
                button_placeholder_id: "spanButtonPlaceHolder",
                //button_text: '<span class="theFont">上传文件</span>',
                //button_text_style: ".theFont {background-image: url('images/btnupload.png');width:301px;height:171px}",
                //button_text_left_padding: 12,
                //button_text_top_padding: 3,

                // The event handler functions are defined in handlers.js
                file_queued_handler: fileQueued,
                file_queue_error_handler: fileQueueError,
                upload_start_handler: uploadStart,
                upload_progress_handler: uploadProgress,
                upload_error_handler: uploadError, //uploadError
                upload_success_handler: uploadOk, //uploadSuccess
                //upload_complete_handler: uploadComplete, //uploadComplete
                file_dialog_complete_handler: fileDialogComplete
            };
            swfu = new SWFUpload(settings);
        };
        function uploadOk(file, serverData) {
            if (serverData != "0") {
                alert("上传完成!" + serverData);
            } else {
                alert("上传失败!");
                swfu.setButtonDisabled(false); //启用上传按钮
            }
        }
    </script> 
    
    
</head>
<body>
    <div id="main_upload">
        <form id="frmMain" action="upload.ashx" runat="server" enctype="multipart/form-data">
        <span id="spanButtonPlaceHolder"></span>
        <div id="divprogresscontainer"></div>
        <div id="divprogressGroup"></div> 
http://www.cnblogs.com/webapi/p/5811304.html </form> </div> </body> </html>

uploadFile.ashx代码

<%@ WebHandler Language="C#" Class="uploadFile" %>

using System;
using System.Web;
using System.IO;

public class uploadFile : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        string PathName = HttpContext.Current.Server.MapPath("file/");
        string NewsName = DateTime.Now.ToString("yyyyMMddHHmmssfff");
        string NewsPathName = Path.Combine(PathName, NewsName);
        DateTime Dtime = System.DateTime.Now;

        HttpPostedFile file = HttpContext.Current.Request.Files["Filedata"];

        if (file != null && file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName))
        {
            file.SaveAs(NewsPathName + Path.GetFileName(file.FileName));
        }
        context.Response.Write("ok123");
        context.Response.End();
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}

 

源码打包下载地址:http://download.csdn.net/detail/pan524365501/9614045

本文地址:http://www.cnblogs.com/webapi/p/5811304.html

 

转载于:https://www.cnblogs.com/webapi/p/5811304.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C#写的ASP.NET到FTP上,文件文件夹都可以。 首先,选择本地文件或者文件夹,然后点击上按钮以后,有一个压缩过程,该过程也有一个实时更新的进度条,并可以显示压缩所需的实时更新的剩余时间,压缩完成以后上,上也是有一个实时更新的进度条,显示剩余上所需时间。上完成以后显示压缩的时间、上的时间和总共所需的时间。 根据文件流上,根据文件进度做的进度条,是真的实实在在的进度条。 代码都有详细的注释,例如: private string ftpUser = "Administrator"; //ftp用户名 private string ftpPassword = "123456"; //ftp密码 public TimeSpan t; //加载进度条总时间 private DateTime startTotalTimeFtp = System.DateTime.Now; private DateTime endTotalTimeFtp = System.DateTime.Now; //压缩用时(为值做准备) //public TimeSpan zipTime; //定义开始时间、结束时间和之间的时间段,以此来估计完成所需剩余时间 DateTime startTime = System.DateTime.Now; DateTime endTime = System.DateTime.Now; TimeSpan TimeSp; //定义剩余时间 string surPlusTime = string.Empty; //判断是否小于1秒所用 int Ti = 0; //实例化类TimeSpanClass TimeSpanClass timeSpanClass = new TimeSpanClass(); 进度条可以实时动态更新,显示剩余时间,剩余时间也跟随进度条实时动态更新,上完成显示上时间。 再次声明,版权所有(花费本人好几个月的心血研究真实的进度条),保证进度条为真正按照文件流的进度所进行,如有问题,可与本人联系!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值