YII+DWZ框架,使用swfupload实现上传

本文介绍如何将SWFUpload文件上传组件整合到DWZ框架中,解决因URL美化导致的上传问题,并提供详细的配置步骤。

DWZ已整合uploadify,但也许是uploadify的swf文件对yii的url美化不支持,设某php文件为上传处理文件,一切正常,但因为涉及权限,我必须把上传处理放在某控制器某动作里(如upload控制器里的image动作:index.php/upload/image),于是悲剧发生了,uploadify不知道是找不到处理文件还是怎样,无穷无处的302错误,网上传得最开的是改.htaccess的,试了不行,PHPSessionID之类就别说了,这些我肯定是设好的,杀了我吧。。。

 

习惯了用swfupload,也熟悉其handler,所以心一横,决定自己把swfupload整合DWZ。

 

1、swfupload的导入,如果把swfupload放进dwz扩展里,然后修改DwzWidget导入js,则在dwz.ui里如何取得swf路径,这个问题我找不到答案,麻烦知道的朋友提醒我一下,谢谢。由于我不知道如何取得swf路径,所以我把swfupload放到extensions外,路径/inc/swfupload,然后修改view文件导入js。

 

2、修改dwz.ui.js,添加swfupload的处理,即从html属性到js属性的切换,由于SWFUpload并非Jquery的扩展,所以把DWZ中惯用的$.fn.xxxxx将不会是true,固采用typeof方法检验swfupload是否已载入。


if (typeof(SWFUpload)!="undefined") {
  $(".forswfupload", $p).each(function(){
   var $this = $(this);
   var options = {
    flash_url: $this.attr("flash_url"),
    flash9_url: $this.attr("flash9_url"),
    upload_url: $this.attr("upload_url"),
    post_params: {},
    file_size_limit: $this.attr("file_size_limit") || "2 MB",
    file_types : $this.attr("file_types") || "*.jpg;*.jpeg;*.gif;*.png;*.pdf",
    file_types_description : $this.attr("file_types_description") || "Image",
    file_upload_limit: 100,
    file_queue_limit: 0,
    custom_settings : {},
    debug: $this.attr("debug") || false,
    button_image_url: $this.attr("button_image_url") || "/images/SmallSpyGlassWithTransperancy_17x18.png",
    button_width: $this.attr("button_width") || "140",
    button_height: $this.attr("button_height") || "18",
    button_placeholder_id: $this.attr("button_placeholder_id"),
    button_text: $this.attr("button_text") || '<span class="sud_btn">本地上传 <span class="sud_sbtn">(2 MB max)</span></span>',
    button_text_style: $this.attr("button_text_style") || '.sud_btn { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .sud_sbtn { font-size: 10pt; }',
    button_text_top_padding: $this.attr("button_text_top_padding") || 0,
    button_text_left_padding: $this.attr("button_text_left_padding") || 18,
    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
    button_cursor: SWFUpload.CURSOR.HAND,

    swfupload_preload_handler : preLoad,
    swfupload_load_failed_handler : loadFailed,
    file_queued_handler : fileQueued,
    file_queue_error_handler : fileQueueError,
    file_dialog_complete_handler : fileDialogComplete,
    upload_start_handler : uploadStart,
    upload_progress_handler : uploadProgress,
    upload_error_handler : uploadError,
    upload_success_handler : uploadSuccess,
    upload_complete_handler : uploadComplete,
    queue_complete_handler : queueComplete
   };
   if ($this.attr("swfupload_preload_handler")) {
    options.swfupload_preload_handler = DWZ.jsoneval_r($this.attr("swfupload_preload_handler"));
   }
   if ($this.attr("swfupload_load_failed_handler")) {
    options.swfupload_load_failed_handler = DWZ.jsoneval_r($this.attr("swfupload_load_failed_handler"));
   }
   if ($this.attr("file_queued_handler")) {
    options.file_queued_handler = DWZ.jsoneval_r($this.attr("file_queued_handler"));
   }
   if ($this.attr("file_dialog_complete_handler")) {
    options.file_dialog_complete_handler = DWZ.jsoneval_r($this.attr("file_dialog_complete_handler"));
   }
   if ($this.attr("upload_start_handler")) {
    options.upload_start_handler = DWZ.jsoneval_r($this.attr("upload_start_handler"));
   }
   if ($this.attr("upload_progress_handler")) {
    options.upload_progress_handler = DWZ.jsoneval_r($this.attr("upload_progress_handler"));
   }
   if ($this.attr("upload_error_handler")) {
    options.upload_error_handler = DWZ.jsoneval_r($this.attr("upload_error_handler"));
   }
   if ($this.attr("upload_success_handler")) {
    options.upload_success_handler = DWZ.jsoneval_r($this.attr("upload_success_handler"));
   }
   if ($this.attr("upload_complete_handler")) {
    options.upload_complete_handler = DWZ.jsoneval_r($this.attr("upload_complete_handler"));
   }
   if ($this.attr("queue_complete_handler")) {
    options.queue_complete_handler = DWZ.jsoneval_r($this.attr("queue_complete_handler"));
   }
   if ($this.attr("post_params")) {
    options.post_params = DWZ.jsoneval_r($this.attr("post_params"));
   }
   if ($this.attr("custom_settings")) {
    options.custom_settings = DWZ.jsoneval_r($this.attr("custom_settings"));
   }
   var temp=new SWFUpload(options);
  });
 }

3、使用时,把上传地址返回文本框定义class="forswfupload",然后定义flash_url,upload_url,holder等属性,post_params需把PHPSESSID设为session_id(),然后在upload_url里session_id($_POST["PHPSESSID"]);

整此已整合成功,具体swfupload的使用在此不多说了,毕竟参数比较多,可结合官方文档进行理解。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值