订阅所有JSP/Servlet的日志 订阅 | 这是最新一篇日志 上一篇 | 下一篇日志 下一篇 ]
JAVA技术

SWFUpload Flash+Javascript无刷新上传应用

附件
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



SWF Settings



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/



平均得分
(0 次评分)





文章来自: 本站原创
标签: JAVASCRIPT 上传 Flash SWFUpload 
评论: 5 | 查看次数: 2559
  • 共有 5 条评论
游客 [2008-10-17 14:33:36]
游客 [2008-08-07 14:56:58]
游客 [2008-07-25 17:37:28]
游客 [2008-06-18 11:26:48]
游客 [2008-06-13 11:53:28]
精油
论文发表
上海翻译公司
上海翻译
英语培训
英语口语
神经性皮炎
皮炎
湿疹
荨麻疹
慢性荨麻疹
藏獒
液压缸
油缸
破碎机
北京旅游
北京旅行社
条码机
条码打印机
条形码打印机
阴茎增大
伟哥
发酵罐
冰淇淋
加盟店
冷饮店
冰淇淋机
冰淇淋粉
冰激凌
大豆床上用品
保健内衣
羊绒内衣
大豆纤维面料
团购礼品
移民
投资移民
商业移民
技术移民
美国移民
澳洲移民
德国移民
英国移民
加拿大移民
热电偶插头
测温线
热电阻
硅碳棒
除湿机
抽湿机
工业除湿机
空气净化器
空气净化机
吸塑机
纸管机
无缝管
合金管
无缝管
无缝钢管
高血压
无线网桥
无线监控
产品设计
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
  • 共有 5 条评论
发表评论
昵 称:  登录
内 容:
选 项:
字数限制 1000 字 | UBB代码 开启 | [img]标签 开启