SWFUpload Flash+Javascript无刷新上传应用
作者:anotherbug 日期:2007-09-29 16:08:17
| swfupload1.jpg(28.6 K) | |
SWFUpload 使用说明如下,附件内容为无刷新使用效果截图,将应用于CJWBlog系统的编辑器。
SWFUpload documentation
Most of the configurations are optional, but if you want to do something more advanced
you probably want the flash to call back to some javascript and present the information in a more informative
way to the user.
Sample configuration
Below is the configuration options used for the example on this page
var swfu;
window.onload = function() {
swfu = new SWFUpload({
upload_script : "/upload.php?id=someid",
target : "SWFUploadTarget",
flash_path : "/jscripts/SWFUpload/SWFUpload.swf",
allowed_filesize : 30720, // 30 MB
allowed_filetypes : "*.*",
allowed_filetypes_description : "All files...",
browse_link_innerhtml : "Browse",
upload_link_innerhtml : "Upload queue",
browse_link_class : "swfuploadbtn browsebtn",
upload_link_class : "swfuploadbtn uploadbtn",
flash_loaded_callback : 'swfu.flashLoaded',
upload_file_queued_callback : "fileQueued",
upload_file_start_callback : 'uploadFileStart',
upload_progress_callback : 'uploadProgress',
upload_file_complete_callback : 'uploadFileComplete',
upload_file_cancel_callback : 'uploadFileCancelled',
upload_queue_complete_callback : 'uploadQueueComplete',
upload_error_callback : 'uploadError',
upload_cancel_callback : 'uploadCancel',
auto_upload : false
});
};
The file object
Most of the callback functions recieves a file object from the flash with the following properties:
- id - the auto-generated unique id for each file
- name - actual filename
- size - filesize
- type - filetype
- creationDate - fhe file creation date
- creator - file creator
UI Settings
Callbacks
- flash_loaded_callback
- upload_file_queued_callback
- upload_file_start_callback
- upload_file_complete_callback
- upload_queue_complete_callback
- upload_dialog_cancel_callback
- upload_file_error_callback
- upload_file_cancel_callback
- upload_progress_callback
- upload_queue_cancel_callback
SWF Settings
- upload_script *
- auto_upload
- allowed_filetypes
- allowed_filetypes_description
- allowed_filesize
- flash_path
- flash_target
- flash_width
- flash_height
- flash_color
Settings
debug
Turn script debugging on/off
- Type: bool
- Default: false
Example:
swfu = new SWFUpload({
...
debug : true
});
target
Target for auto-generated upload/browse links
- Type: string
- Default: null
Example:
swfu = new SWFUpload({
...
target : "somedivid"
});
create_ui
Auto-generate UI. Use this if you want to replace an existing form
- Type: bool
- Default: true
Example:
swfu = new SWFUpload({
...
create_ui : true
});
browse_link_class
CSS-class given to auto-generated browse link
- Type: string
- Default: SWFBrowseLink
Example:
swfu = new SWFUpload({
...
browse_link_class : "yourbrowsebtnclass"
});
upload_link_class
CSS-class given to auto-generated upload link
- Type: string
- Default: SWFUploadLink
Example:
swfu = new SWFUpload({
...
upload_link_class : "youruploadbtnclass"
});
browse_link_innerhtml
innerHTML for generated browse link
- Type: string
- Default: <span>Browse...</span>
Example:
swfu = new SWFUpload({
...
browse_link_innerhtml : "<h1>Browse for files</h1>"
});
upload_link_innerhtml
innerHTML for generated upload link
- Type: string
- Default: <span>Upload</span>
Example:
swfu = new SWFUpload({
...
upload_link_innerhtml : "<h1>Upload files</h1>"
});
flash_loaded_callback - required
Invoked when the flash is loaded. This function resides within SWFUpload, so it just needs to be called with the correct instance name
- Returns: void
- Default: null
Example:
swfu = new SWFUpload({
...
flash_loaded_callback : "swfu.flashLoaded"
});
upload_file_queued_callback
Invoked when each file is added to the queue
Example:
function fileQueuedFunction(file, queuelength) {
var ul = document.getElementById("yourfileul");
var li = document.createElement("li");
ul.appendChild(document.createTextNode(file.name));
}
swfu = new SWFUpload({
...
upload_file_queued_callback : "fileQueuedFunction"
});
upload_file_start_callback
Invoked when upload starts
Example:
function fileStartFunction(file, position, queuelength) {
alert(file.name + " " + position + " of " + queuelength);
}
swfu = new SWFUpload({
...
upload_file_start_callback : "fileStartFunction"
});
upload_file_complete_callback
Invoked when each file is completed
Example:
function fileCompletedFunction(file) {
alert(file.name + " completed");
}
swfu = new SWFUpload({
...
upload_file_complete_callback : "fileCompletedFunction"
});
upload_queue_complete_callback
Invoked when upload queue is complete
Example:
function queueCompletedFunction() {
alert("Queue completed");
}
swfu = new SWFUpload({
...
upload_queue_complete_callback : "queueCompletedFunction"
});
upload_progress_callback
Called with regular updates on progress
Example:
function uploadProgressFunction(file, bytesloaded, bytestotal) {
var progress = document.getElementById("yourprogressid");
var percent = Math.ceil((bytesloaded / bytestotal) * 100);
progress.innerHTML = percent + "%";
}
swfu = new SWFUpload({
...
upload_progress_callback : "uploadProgressFunction"
});
upload_dialog_cancel_callback
Invoked when cancel btn in dialog is clicked
Example:
function dialogCancelFunction() {
alert("Browse cancelled");
}
swfu = new SWFUpload({
...
upload_dialog_cancel_callback : "dialogCancelFunction"
});
upload_file_error_callback
Invoked on error
Example:
function errorsFunction(errcode, file, msg) {
alert(errcode + ", " file.name + ", " + msg);
}
swfu = new SWFUpload({
...
upload_file_error_callback : "errorsFunction"
});
upload_file_cancel_callback
Invoked when a file upload is cancelled
Example:
function cancelFileFunction(file, queuelength) {
alert("File: " + file.name + " cancelled");
}
swfu = new SWFUpload({
...
upload_file_cancel_callback : "cancelFileFunction"
});
upload_queue_cancel_callback
Invoked when upload queue is cancelled
Example:
function cancelQueueFunction() {
alert("Queue cancelled");
}
swfu = new SWFUpload({
...
upload_queue_cancel_callback : "cancelQueueFunction"
});
upload_script - required
Path to the script that recieves the uploaded files from flash.
- Type: string
Example:
swfu = new SWFUpload({
...
upload_script : "upload.php?param1=foo"
});
Code snippets to retrieve posted data
php:
$fileObject = $_FILES['Filedata'];
C#:
HttpPostedFile fileObject = Request.Files["Filedata"];
VB.NET
Dim fileObject As HttpPostedFile
fileObject = Request.Files("Filedata")
Ruby on rails
fileObject = params[:Filedata]
auto_upload
Start upload directly or require upload button.
- Type: bool
- Default: false
Example:
swfu = new SWFUpload({
...
auto_upload : true
});
allowed_filetypes
List of allowed filetypes
- Type: string
- Default: "*.*"
Example:
swfu = new SWFUpload({
...
allowed_filetypes : "*.jpg;*.gif;*.pdf"
});
allowed_filetypes_description
Description for allowed filetypes, displayed in the drop-down in the file dialog
- Type: string
- Default: "All files"
Example:
swfu = new SWFUpload({
...
allowed_filetypes_description : "Description filetypes"
});
allowed_filesize
Max allowed filesize in kilobytes
- Type: int
- Default: 1024
Example:
swfu = new SWFUpload({
...
allowed_filesize : "30000"
});
flash_path
Path to flash-file
- Type: string
- Default: "jscripts/SWFUpload/SWFUpload.swf"
Example:
swfu = new SWFUpload({
...
flash_path : "folder/swf/myrenamedswfupload.swf"
});
<script type="text/javascript"><!--
google_ad_client = "pub-5044040179190261";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
google_ad_channel = "";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
Tips & Tricks
Get the session-id from ruby on rails apps:
blog.inquirylabs.com
Error handling
There is a bit of simple error handling built-in, but this can be expanded by using the
upload_error_callback. The SWF will return a few different error codes depending on
what goes wrong. Here is a short explanation:
- -10: HTTP error, also returns the http error code (404 etc)
- -20: Custom error code if no backend file is specified
- -30: IO-error
- -40: Security error
- -50: Filesize exceeds limit
The error always contains one of these codes and the file object that caused the error,
some, like the http error also contains a message (the http error code).
Known bugs
If you are using Apache with mod_security this will not work, you need to put
the following in your .htaccess file to disable mod_security:
SecFilterEngine Off
SecFilterScanPOST Off
Disabling mod_security isn't allowed on some shared hosts, and only do this if you know what you are doing.
This is due to a bug in the way that flash sends the headers back to the server according to the Flash 8 documentation
IE Out of memory-bug
When using multiple instances of SWFUpload on the same page IE doesn't remove the ExternalInterface functions correctly, use this "hack" to temporarily fix it until Adobe sorts out their player:
window.onbeforeunload = function() {
if (document.all)
window.onunload = null;
}
Updating ScriptLimits
If you have downloaded the source-release you will have to manually update the ScriptLimit tag to prevent the "A script on this site is running slowly"-alert, you can get rid of that
and find more information about the problem here http://www.buraks.com/swfsli/
- 共有 5 条评论
- 共有 5 条评论
订阅
上一篇
|

文章来自:
标签: 
高低温试验箱
振动试验台
恒温恒湿试验箱
恒温恒湿箱
恒温箱
振动台
盐雾箱
老化台
盐雾试验箱
高低温箱
低温试验箱
振动试验机
合同纠纷
房产纠纷
劳动纠纷
房地产律师
制氮机
在职研究生
液体壁纸
清水模板
冷弯型钢
牛仔服
牛仔服装厂
牛仔休闲
牛仔裤
牛仔品牌
牛仔专卖店
节能胶带机
胶带机价格
虹吸
虹吸雨水
虹吸排水
有压流
同层排水
恒温器
马达保护器
热保护器
温度开关
温控器
过流保护器
真空泵
藏獒
全自动表面张力仪/界面张力仪
舞台设计
烧烤网
振动筛网
拖链
光纤熔接机
光缆监测系统
时光域反射仪
不锈钢反应釜
风机
捏合机
制氮机
上海VI设计
上海企业形象设计
上海印刷设计
上海画册设计
上海包装设计
补偿导线
铂铑热电偶
OMEGA测温线
电子签名
数字签名
电子签章
电子印章
IT外包
阴茎增大
乐泰
乐泰胶
loctite
芳香疗法
广东藏獒
五金工具
进口五金工具
五金工具代理
深圳室内环境检测
反应锅
不锈钢反应锅
列管冷凝器
螺旋板换热器
清洗
清洗公司
管道清洗
空调清洗
中央空调清洗
锅炉清洗
化学清洗
中央空调风管清洗
艾力达
万艾可
西力士
冰淇淋加盟
意大利冰淇淋
冰淇淋连锁
韩国冰淇淋
冰淇淋专卖店
脑黄金冰淇淋
皮炎
湿疹
荨麻疹
Носки согревающие
Оздоровительное изделие
Халат купальный
Изделие из ангоры
Майка из ангоры
注册英国公司
英国公司注册
英国公司注册
美国公司注册
BVI公司注册
注册BVI公司
通信仪表
以太网测试仪
2M误码仪
SDH测试仪
ADSL测试仪
信令仪
PCM测试仪
电池测量仪
传输分析仪
切换设备
远动信号测试
太阳能路灯
上海华宇物流公司
上海华宇物流
华宇物流公司
华宇物流
论文发表
上海翻译公司
上海翻译
英语培训
英语口语
神经性皮炎
皮炎
湿疹
荨麻疹
慢性荨麻疹
藏獒
液压缸
油缸
破碎机
北京旅游
北京旅行社
条码机
条码打印机
条形码打印机
阴茎增大
伟哥
发酵罐
冰淇淋
加盟店
冷饮店
冰淇淋机
冰淇淋粉
冰激凌
大豆床上用品
保健内衣
羊绒内衣
大豆纤维面料
团购礼品
移民
投资移民
商业移民
技术移民
美国移民
澳洲移民
德国移民
英国移民
加拿大移民
热电偶插头
测温线
热电阻
硅碳棒
除湿机
抽湿机
工业除湿机
空气净化器
空气净化机
吸塑机
纸管机
无缝管
合金管
无缝管
无缝钢管
高血压
无线网桥
无线监控
产品设计
men spa beijing
men massage beijing
pearl jewelry
Beijing Tour
china Tour
beijing Tour
china Tour
beijing Tour
China Necklace Wholesale
China Bracelet Wholesale
China Ring wholesale
China gemstone beads wholesale
China Jewelry Accessories wholesale
China Semiprecious beads wholesale
replica handbag
replica tiffany
replica watches
louis vuitton replica
chanel replica
gucci replica
Chinese language
Chinese learn
learning Chinese
learn mandarin
ecosway
gasifier
coal gas
coal gasification
pro dj cases
beijing tour
beijing tours
beijing travel
beijing tours
china tour
beijing
china tours
china travel
beijing china
china beijing
beijing hotel
beijing hotels
China Flights
carved fireplace
stone bathtub
marble fountain
marble bench
marble fireplace
marble sculpture
marble columns
marble lions
marble doorway
marble gazebo
marble pillar
marble fireplace surround
marble statue
marble bathtub