<%@ 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示例-Mzwu.Com</title>
<script type="text/javascript" src="js/swfupload.js"></script>
<script type="text/javascript">
var swfu;
window.onload = function () {
swfu = new SWFUpload({
// Backend Settings
upload_url: "upload.ashx",
post_params : {
"ASPSESSID" : "<%=Session.SessionID %>"
},
// File Upload Settings
file_size_limit : "5 MB",
file_types : "*.jpg",
file_types_description : "JPG Images",
// Event Handler Settings
file_dialog_complete_handler : function(numFilesSelected, numFilesQueued) { if (numFilesQueued > 0)this.startUpload();},
upload_success_handler : function(file,responseText){alert(file.name + " saveas " + responseText);},
// Button settings
button_image_url : "images/XPButtonNoText_160x22.png",
button_placeholder_id : "spanButtonPlaceholder",
button_width: 160,
button_height: 22,
button_text : '上传文件(<3M)',
button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 14pt; } .buttonSmall { font-size: 10pt; }',
button_text_top_padding: 1,
button_text_left_padding: 5,
// Flash Settings
flash_url : "swf/swfupload.swf", // Relative to this file
// Debug Settings
debug: false
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="spanButtonPlaceholder"></div>
</div>
</form>
</body>
</html>upload.ashx:
<%@ WebHandler Language="C#" Class="Upload" %>
using System;
using System.Web;
using System.IO;
public class Upload : IHttpHandler {
public void ProcessRequest (HttpContext context) {
try
{
HttpPostedFile upload = context.Request.Files["Filedata"];
string name = DateTime.Now.Ticks.ToString() + Path.GetExtension(upload.FileName);
upload.SaveAs(Path.Combine(context.Server.MapPath("upload"), name));
context.Response.StatusCode = 200;
context.Response.Write(name);
}
catch { }
}
public bool IsReusable {
get {
return false;
}
}
}最后,web.config中configuration增加以下节点:
<location path="Upload.ashx">
<system.web>
<httpRuntime maxRequestLength="3100" executionTimeout="300" />
</system.web>
</location>完成!点击下载示例
SWFUpload官方站点:http://swfupload.org/
SWFUpload源码下载:http://swfupload.googlecode.com/
评论(0)
暂无评论。