Web方式的文件上传一直是个比较麻烦的问题,尤其是大尺寸(占用磁盘空间大)文件,幸亏有牛人引领Ajax潮流的到来,我们也有幸得以发挥。
?>
configuration>
configSections>
section name="extnet" type="Ext.Net.GlobalConfig" requirePermission="false" />
configSections>
system.web>
httpRuntime executionTimeout="5400" maxRequestLength="20480000" useFullyQualifiedRedirectUrl="false" />
compilation debug="true" targetFramework="4.0" />
pages>
controls>
add assembly="Ext.Net" namespace="Ext.Net" tagPrefix="ext" />
controls>
pages>
httpHandlers>
add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false" />
httpHandlers>
httpModules>
add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" />
httpModules>
system.web>
appSettings>
add key="UploadPath" value="UpLoadFiles" />
appSettings>
extnet theme="Default" />
system.webServer>
validation validateIntegratedModeConfiguration="false" />
modules>
add name="DirectRequestModule" preCondition="managedHandler" type="Ext.Net.DirectRequestModule, Ext.Net" />
modules>
handlers>
add name="DirectRequestHandler" verb="*" path="*/ext.axd" preCondition="integratedMode" type="Ext.Net.ResourceHandler" />
handlers>
system.webServer>
configuration>
>
代码如下 | 复制代码 |
|
代码如下 | 复制代码 |
|
代码如下 | 复制代码 |
%>
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.**w*3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
html xmlns="http://www.w***3.org/1999/xhtml">
head runat="server">
title>SimpleSwfupload>
script type="text/javascript" src="swfupload/swfupload.js">>
script type="text/javascript" src="js/swfuploadevent.js">>
script type="text/javascript" src="js/InitSwfUpload.js">>
script type="text/javascript" src="Simple.js">>
style type="text/css">
.ContentsStyle
{
font-size: 14px;
}
>
head>
body>
form id="form1" runat="server">
ext:ResourceManager ID="ResourceManager1" runat="server">
Listeners>
%>
|
代码如下
复制代码
///
///
///
///
var swfu; //全局变量
//获取初始化设置项
function getSettings() {
return settings = {//此处所有的配置项在SWF说明文档中有,详见本项目中SWFUpload Document.html
upload_url: "FileUpload.ashx",
flash_url: "swfupload/swfupload.swf",
flash9_url: "swfupload/swfupload_fp9.swf",
file_post_name: "Filedata",
use_query_string: false,
requeue_on_error: false,
http_success: [201, 202],
assume_success_timeout: 0,
file_types: "*.*",
file_types_description: "所有文件",
file_size_limit: "10 GB",
file_upload_limit: 0,
file_queue_limit: 0,
debug: false,
//Added in v2.2.0 This boolean setting indicates whether a random value should be added to the Flash
//URL in an attempt to prevent the browser from caching the SWF movie. This works around a bug in some IE-engine based browsers.
//Note: The algorithm for adding the random number to the URL is dumb and cannot handle URLs that already have some parameters.
prevent_swf_caching: true,
//A boolean value that indicates whether SWFUpload should attempt to convert relative URLs used by the Flash Player to absolute URLs.
//If set to true SWFUpload will not modify any URLs. The default value is false.
preserve_relative_urls: false,
//按钮部分
button_placeholder_id: "btnUploadFile", //上传按钮所占用的区域
button_image_url: "img/ButtonNoText_75x21.png", //上传按钮图片效果
button_width: 77, //上传按钮宽
button_height: 21, //上传按钮高
button_text: "添加附件",
button_text_left_padding: 10,
button_text_top_padding: 1,
button_action: SWFUpload.BUTTON_ACTION.SELECT_FILES,
button_disabled: false,
button_cursor: SWFUpload.CURSOR.HAND,
button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
//以下是SWFUpload的事件,详见说明文档
swfupload_preload_handler: swfupload_preload_function,
swfupload_load_failed_handler: swfupload_load_failed_function,
file_queue_error_handler: file_queue_error_function,
file_dialog_complete_handler: file_dialog_complete_function,
upload_progress_handler: upload_progress_function,
upload_error_handler: upload_error_function,
upload_success_handler: upload_success_function,
upload_complete_handler: upload_complete_function,
swfupload_loaded_handler: swfupload_loaded_function,
mouse_click_handler: mouse_click_function,
mouse_over_handler: mouse_over_function,
mouse_out_handler: mouse_out_function,
file_dialog_start_handler: file_dialog_start_function,
file_queued_handler: file_queued_function,
upload_start_handler: upload_start_function,
debug_handler: debug_function
};
}
function InitSwf() {
if (swfu) {//初次需要销毁,不这么做会有BUG,忘了是什么,可以试试看
swfu.destroy();
}
swfu = new SWFUpload(getSettings()); //初始化SWFUpload对象
}
添加swfuploadevent.js
代码如下
复制代码
///
///
///
///
function swfupload_preload_function() {
if (!this.support.loading) {
Ext.MessageBox.alert("温馨提示", "您的Flash版本过低(支持9.028及更高版本),
请下载最新版Flash.");
//alert("You need the Flash Player 9.028 or above to use SWFUpload.");
return false;
}
}
//加载失败
function swfupload_load_failed_function() {
var t = this;
}
//加载后
function swfupload_loaded_function() {
var t = this;
}
function mouse_click_function() {
var t = this;
}
function mouse_over_function() {
var t = this;
}
function mouse_out_function() {
var t = this;
}
function file_dialog_start_function() {
var t = this;
}
function file_queued_function(file) {
var t = this;
}
//文件队列错
function file_queue_error_function(file, errorCode, message) {
var t = this;
}
//文件上传完成
function file_dialog_complete_function(fileSelectedCount, numberOfFilesQueued, totalNumberOfFilesInTheQueued) {
if (fileSelectedCount > 0) {
swfu.startUpload();//如果队列中还有未上传文件,则继续,若没有,一次只能上传一个文件
}
}
//开始上传
function upload_start_function(file) {
pbar.show();
btnCancelFileUpload.show();
}
//更新进度条
function upload_progress_function(file, completeBytes, totalBytes) {
var percent = Math.ceil((completeBytes / totalBytes) * 100);
pbar.updateProgress(percent / 100, file.name + ":" + percent + "%");
}
function upload_error_function(file, errorCode, message) {
var t = this;
}
//上传成功
function upload_success_function(file, data, received) {
if (received) {
var TopicRecord = Ext.data.Record.create([
{ name: 'ID', type: 'string' },
{ name: 'FileName', type: 'string' },
{ name: 'FileSize', type: 'int' },
{ name: 'FileExtension', type: 'string' },
{ name: 'FileCreationDate', type: 'date' },
{ name: 'FileModificationDate', type: 'date' },
{ name: 'FilePath', type: 'string' },
{ name: 'FileIndex', type: 'int' },
{ name: 'FileId', tyep: 'int' }
]);
var myNewRecord = new TopicRecord({
ID: file.id,
FileName: file.name,
FileSize: file.size,
FileExtension: file.type,
FileCreationDate: file.creationdate,
FileModificationDate: file.modificationdate,
FilePath: data,
FileIndex: file.index,
FileId: file.index
});
storeFiles.add(myNewRecord);//向Store中添加一行数据
}
}
//全部上传完成
function upload_complete_function(file) {
btnCancelFileUpload.hide();
pbar.reset();
pbar.updateText("");
pbar.hide();
swfu.startUpload();
}
function debug_function() {
var t = this;
}
function CancelFileUpload() {
var s = swfu;
swfu.cancelUpload();
}
添加Simple.js
代码如下
复制代码
///
///
///
///
//删除动作
function gpFlilesDelete(cmd, record, rowIndex) {
if (cmd === 'delete') {
storeFiles.remove(record);//移除record
}
}
//Store中移除了数据
function storeFilesRemoveEvent(store, record, rowIndex) {
var recordCount = store.getCount();
if (recordCount //调用后端Direct方法删除文件
Ext.net.DirectMethods.DeleteFile(record.data.FilePath, record.data.FileName);
}
//Store中添加了数据
function storeFilesAddEvent(store, record, rowIndex) {
gpFiles.show();
}
//换算文件大小
function renderSize(value, p, record) {
if (null == value || value == '') {
return "0 Bytes";
}
var unitArr = new Array("Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
var index = 0;
var srcsize = parseFloat(value);
var quotient = srcsize;
while (quotient > 1024) {
index += 1;
quotient = quotient / 1024;
}
return roundFun(quotient, 2) + " " + unitArr[index];
}
/*
四舍五入保留小数位数
numberRound 被处理的数
roundDigit 保留几位小数位
*/
function roundFun(numberRound, roundDigit) {
if (numberRound >= 0) {
var tempNumber = parseInt((numberRound * Math.pow(10, roundDigit) + 0.5)) / Math.pow(10, roundDigit);
return tempNumber;
} else {
numberRound1 = -numberRound
var tempNumber = parseInt((numberRound1 * Math.pow(10, roundDigit) + 0.5)) / Math.pow(10, roundDigit);
return -tempNumber;
}
}
添加后端cs方法
代码如下 | 复制代码 |
using System; using Ext.Net; namespace SwfUploadDemo { public partial class Simple : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } /// |
代码如下 | 复制代码 |
using System; using System.Web; using System.IO; namespace SwfUploadDemo { /// |
樱花校园模拟器4399中文版
樱花校园模拟器4399中文版,十分奇趣好玩的3d校园冒险模拟
我的暑假秘密回忆繁星新春版
我的暑假秘密回忆繁星新春版是一款少女模拟养成类休闲游戏。这款
樱花校园模拟器国际版
樱花校园模拟器国际版,一个超级自由超级好玩的自由恋爱模拟的游
饥荒海难九游版
饥荒海难九游版,带你去真实的海岛上感受一下什么才是真正的孤岛
盖瑞模组体验版最新版
盖瑞模组体验版是玩法非常丰富多元化的沙盒建造游戏,玩家可以在