前陣子有人提到這個上傳工具,小弟沒玩過就給它抓下來試試
SWFUpload可以支援多檔上傳功能,還不錯用,小弟分享一下試用的結果
首先要將官網的Demo Sample抓下來,如下所示:
SWFUpload下載網址:http://swfupload.googlecode.com
SWFUpload下載檔案:SWFUpload-Samples v2.1.0.Release.zip
在\SWFUpload Samples v2.1.0\demos\applicationdemo.net目錄裡有下列檔案
接下來只要修改Default這支程式就可以了..我只增加了儲存選取檔案的功能..
和清除目前選取檔案的功能..更多的功能就要自己去修改了...
asp.net(c#)
Default.aspx
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <!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>SWFUpload Revision v2.1.0 Application Demo (ASP.Net 2.0)</title>
- <link href="css/default.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="swfupload/swfupload.js"></script>
- <script type="text/javascript" src="js/handlers.js"></script>
- <script type="text/javascript">
- var swfu;
- window.onload = function () {
- swfu = new SWFUpload({
- // Backend Settings
- upload_url: "upload.aspx", // Relative to the SWF file
- post_params : {
- "ASPSESSID" : "<%=Session.SessionID %>"
- },
- // File Upload Settings
- file_size_limit : "2048", // 2MB
- file_types : "*.jpg",
- file_types_description : "JPG Images",
- file_upload_limit : "0", // Zero means unlimited
- // Event Handler Settings - these functions as defined in Handlers.js
- // The handlers are not part of SWFUpload but are part of my website and control how
- // my website reacts to the SWFUpload events.
- file_queue_error_handler : fileQueueError,
- file_dialog_complete_handler : fileDialogComplete,
- upload_progress_handler : uploadProgress,
- upload_error_handler : uploadError,
- upload_success_handler : uploadSuccess,
- upload_complete_handler : uploadComplete,
- // Flash Settings
- flash_url : "swfupload/swfupload_f9.swf", // Relative to this file
- custom_settings : {
- upload_target : "divFileProgressContainer"
- },
- // Debug Settings
- debug: false
- });
- }
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div id="header">
- <h1 id="logo"><a href="../">SWFUpload</a></h1>
- <div id="version">v2.1.0 Beta</div>
- </div>
- <div id="content">
- <h2>Application Demo (ASP.Net 2.0)</h2>
- <div id="swfu_container" style="margin: 0px 10px;">
- <div>
- <button id="btnBrowse" type="button" style="padding: 5px;" onclick="swfu.selectFiles(); this.blur();"><img src="images/page_white_add.png" style="padding-right: 3px; vertical-align: bottom;" alt="Add Icon" />Select Images <span style="font-size: 7pt;">(2 MB Max)</span></button>
- <asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save Select Images" Width="150px" />
- <asp:Button ID="btnClear" runat="server" Text="Clear Select Images" OnClick="btnClear_Click" Width="150px" /></div>
- <div id="divFileProgressContainer" style="height: 75px;"></div>
- <div id="thumbnails"></div>
- </div>
- </div>
- </form>
- </body>
- </html>
Default.aspx.cs
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Collections.Generic;
- using System.IO;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- // Clear the user's session
- if (!IsPostBack)
- {
- Session.Clear();
- }
- }
- protected void btnSave_Click(object sender, EventArgs e)
- {
- if (Session["file_info"] != null)
- {
- List<Thumbnail> thumbnails = Session["file_info"] as List<Thumbnail>;
- string UploadPath = Server.MapPath("upload/");
- foreach (Thumbnail img in thumbnails)
- {
- FileStream fs = new FileStream(UploadPath + img.ID + ".jpg", FileMode.Create);
- BinaryWriter bw = new BinaryWriter(fs);
- bw.Write(img.Data);
- bw.Close();
- fs.Close();
- }
- Session.Clear();
- }
- }
- protected void btnClear_Click(object sender, EventArgs e)
- {
- Session.Clear();
- }
- }
執行結果:
參考網址:http://www.cnblogs.com/icejd/archive/2008/12/23/1360214.html