多附件上传例子
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="uploadify.aspx.cs" Inherits="uploadify" %> <!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>uploadify用法</title> <link href="JS/jquery.uploadify-v2.1.0/example/css/default.css" rel="stylesheet" type="text/css" /> <link href="JS/jquery.uploadify-v2.1.0/uploadify.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="JS/jquery.uploadify-v2.1.0/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="JS/jquery.uploadify-v2.1.0/swfobject.js"></script> <script type="text/javascript" src="JS/jquery.uploadify-v2.1.0/jquery.uploadify.v2.1.0.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#uploadify").uploadify({ 'uploader': 'JS/jquery.uploadify-v2.1.0/uploadify.swf', 'script': 'UploadHandler.ashx', 'scriptData': { billNum: $("#hdBillNum").val() },//传递的参数 'cancelImg': 'JS/jquery.uploadify-v2.1.0/cancel.png', 'folder': 'UploadFiles/store/', 'queueID': 'fileQueue', 'auto': false, 'multi': true, //多选 'width': '100', 'height': '27', 'buttonImg': 'JS/jquery.uploadify-v2.1.0/fj.gif', 'queueSizeLimit': 15, //允许上传的最大个数 'simUploadLimit': 15//同时上传的个数 }); }); function Button1_onclick() { debugger; $('#uploadify').uploadifyUpload(); } </script> </head> <body> <form id="form1" runat="server"> <input type="hidden" id="hdBillNum" runat="server"/> <div> <table class="TableBorder" id="tabAttachment"> <tr> <td align="right"> 附件: </td> <td> <input type="file" name="uploadify" id="uploadify" /> </td> </tr> <tr> <td align="right"> </td> <td align="left"> <div id="fileQueue"> </div> </td> <td> <input id="Button1" type="button" value="上传附件" onclick="return Button1_onclick()" /><br /></td> </tr> </table> </div> </form> </body> </html>
上面是前台
后台:
一般处理程序uploadHander.ashx
<%@ WebHandler Language="C#" Class="UploadHandler" %>
using System;
using System.Web;
using System.IO;
using System.Web.SessionState;
using System.Data;
public class UploadHandler : IHttpHandler, IReadOnlySessionState
{
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
HttpPostedFile file = context.Request.Files["Filedata"];
string uploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"]);//UploadFiles\propertyManage
if (file != null)
{
//file.SaveAs(uploadPath + newFileName); //上传文件
//sql="Insert into "//插入数据库
//context.Response.Write("1"); //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
}
else
{
context.Response.Write("0");
}
}
public bool IsReusable {
get {
return false;
}
}
}
浙公网安备 33010602011771号