惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Help Net Security
Help Net Security
P
Privacy International News Feed
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
AWS News Blog
AWS News Blog
K
Kaspersky official blog
A
Arctic Wolf
Latest news
Latest news
T
Threat Research - Cisco Blogs
L
LINUX DO - 最新话题
P
Privacy & Cybersecurity Law Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
月光博客
月光博客
N
News and Events Feed by Topic
Jina AI
Jina AI
博客园 - 司徒正美
WordPress大学
WordPress大学
罗磊的独立博客
雷峰网
雷峰网
AI
AI
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Security @ Cisco Blogs
博客园 - 三生石上(FineUI控件)
H
Heimdal Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cisco Blogs
博客园 - 【当耐特】
The Hacker News
The Hacker News
有赞技术团队
有赞技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Schneier on Security
Schneier on Security
博客园 - Franky
S
SegmentFault 最新的问题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cloudbric
Cloudbric
爱范儿
爱范儿
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Secure Thoughts
Last Week in AI
Last Week in AI
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Know Your Adversary
Know Your Adversary
Google DeepMind News
Google DeepMind News

博客园 - Ferry

ASP.NET网站权限设计实现(三)——套用JQuery EasyUI列表显示数据、分页、查询 ASP.NET网站权限设计实现(二)——角色权限绑定 ASP.NET读取网络图片并在页面上显示 ASP.NET网站权限设计实现(一)——使用PowerDesigner进行数据库设计 Visual Studio 2010 架构图之用例图(UML Use Case Diagram) ASP.NET MVC3 新的视图引擎(View Engine) 一个德国人图解中西文化差异(值得一看) 微软AJAX CDN(内容分发网络) 注册使用GAC—Global Assembly Cache(.NET) ASP.NET 递归将分类绑定到 TreeView - Ferry 新浪微博PC客户端(DotNet WinForm版)——功能实现分解介绍 新浪微博PC客户端(DotNet WinForm版)—— 初探 C#:30行数据插入到数据库中的效率测试-一行行执行、构造SQL一次执行、SqlBulkCopy C#使用GMAIL群发带附件邮件的例子 ASP.NET Web 应用开发实战快速上手系列 3—C#面向对象编程纲要-类 ASP.NET4.0中客户端ID的生成 在高优先级下运行应用程序 学习使用NHibernate2.1.0Beta1(续七)— 单例模式 ASP.NET Web 应用开发实战快速上手系列 2——C#基础
ASP.NET带进度条多文件上传
Ferry · 2010-10-26 · via 博客园 - Ferry

一、资源

1)Uploadify v2.1.0,可以到这里下载:www.uploadify.com。

2)JQuery EasyUI ,下载地址:http://jquery-easyui.wikidot.com/download

二、预览

1)初始界面 

 

2) 点击【BROWSE】选择多文件

 

3) 选择的文件列表,点击【全部上传】开始上传文件队列

 

 三、代码

1)解压jquery.uploadify-v2.1.0.zip,复制example\index.php的代码,对应粘贴到你的页面(HTML或ASPX),注意拷贝相应的CSS、JS和SWF文件到你的项目对应目录

2)解压 JQuery EasyUI.zip,拷贝相应的CSS、JS文件到你的项目对应目录,并在你的页面中的<title></title>标签中添加引用

HTML:

<!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>
    
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
<title>多文件上传 - 可设置多文件还是单文件上传,以及上传文件的大小</title>
    
<!--JQuery-->
    
<script type="text/javascript" src="scripts/jquery-1.4.2.min.js"></script>
    
<!--JQuery EasyUI-->
    
<link href="css/easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    
<link href="css/easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    
<script type="text/javascript" src="scripts/jquery.easyui.min.js"></script>
    
<!--MultiUpload-->
    
<link href="css/default.css" rel="stylesheet" type="text/css" />
    
<link href="css/uploadify.css" rel="stylesheet" type="text/css" />
    
<script type="text/javascript" src="scripts/swfobject.js"></script>
    
<script type="text/javascript" src="scripts/jquery.uploadify.v2.1.0.min.js"></script>
    
<script type="text/javascript">
        $(document).ready(
function () {
            $(
"#uploadify").uploadify({
                
'uploader''Flash/uploadify.swf',
                
'script''UploadHandler.ashx',
                
'cancelImg''Images/cancel.png',
                
'folder''Uploads',
                
'queueID''fileQueue',
                
//'fileDesc': '*.rar;*.jpg;*.gif',
                //'fileExt': '*.rar;*.jpg;*.gif',
                'sizeLimit''2097152'//2M
                'auto'false,
                
'multi'true,
                
'onError'function (a, b, c, d) {
                    
if (d.status == 404)
                        alert(
'Could not find upload script.');
                    
else if (d.type === "HTTP")
                        alert(
'error ' + d.type + "" + d.status);
                    
else if (d.type === "File Size")
                        alert(c.name 
+ ' ' + d.type + ' Limit: ' + Math.round(d.sizeLimit / 1024+ 'KB');
                    
else
                        alert(
'error ' + d.type + "" + d.info);
                }
            });
        });
</script>
</head>
<body>
    
<div class="easyui-tabs" style="width: 400px; height: 300px;padding-bottom:5px">
        
<div title="上传文件列表" id="fileQueue" style="padding: 10px;">
            
        
</div>
        
<!--<div title="已上传文件" id="fileUploaded" closable="false" style="padding: 10px;">
            
        </div>
-->
    
</div>
    
<input type="file" name="uploadify" id="uploadify" />
    
<p>
        
<href="javascript:$('#uploadify').uploadifyUpload()">全部上传</a><href="javascript:$('#uploadify').uploadifyClearQueue()">
            全部取消
</a>
    
</p>
</body>
</html>

 UploadHandler.ashx文件代码:

<%@ WebHandler Language="C#" Class="UploadHandler" %>
using System;
using System.IO; 
using System.Net;
using System.Web; public class UploadHandler : IHttpHandler
{
    
public void ProcessRequest(HttpContext  context) 
    {
        context.Response.ContentType 
= "text/plain"
        context.Response.Charset 
= "utf-8";
        
        
//获取上传文件队列
        HttpPostedFile oFile = context.Request.Files["Filedata"];
        
if (oFile != null)
        {
            
string topDir = context.Request["folder"];
            
//创建顶级目录
            if (!Directory.Exists(HttpContext.Current.Server.MapPath(topDir)))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(topDir));
            } 
            
            
//当天上传的文件放到已当天日期命名的文件夹中
            string dateFolder = HttpContext.Current.Server.MapPath(topDir) + "\\" + DateTime.Now.Date.ToString("yyyy-MM-dd");
            
if (!Directory.Exists(dateFolder))
            {
                Directory.CreateDirectory(dateFolder);
            }
            oFile.SaveAs(dateFolder 
+ "\\" + oFile.FileName);
            context.Response.Write(
"1");
            
        } 
        
else 
        { 
            context.Response.Write(
"0"); 
        }
    }
    
public bool IsReusable
    { 
        
get  { return false; }
    } 
}

下一篇谈一下如何让上传的文件跟特定的数据库信息关联。