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

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的使用在此不多说了,毕竟参数比较多,可结合官方文档进行理解。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这份DWZ代码是我个人一直使用的,DWZ对各版本IE的兼容性是比较好的,我的代码在IE6下也基本能正常使用,这是一直舍不得换其它框架的主要原因。 压缩包是完整的jfinal+dwz的测试性小代码,直接导入myeclipse,运行DwzConfig.java,访问http://localhost:8888/admin就可以进入页面。 代码例子是JAVA的,dwz,ztree等是前台的东西,和后台没有关系。不管.net还是php都通用,请根据使用的平台,修改发布WebRoot下的文件,修改admin.jsp就可以。 页面集成了ztree3.3,kindeditor,My97DatePicker的使用例子。 本代码解决了DWZ集成ztree时,对于未展开的菜单点击后target无效的问题。以下是使用例子: var zNodes =[ { id:1, pId:0, name:"菜单管理(不响应点击)", url:"#",open:false}, { id:2, pId:1, name:"菜单2(响应点击)", url:"articleAddEdit.html", target:"navTab", rel:"articleAddEdit2",open:false}, { id:3, pId:2, name:"菜单3(不响应点击)", url:"#", target:"navTab", rel:"articleAddEdit3",open:false}, { id:4, pId:3, name:"文章管理4", url:"articleAddEdit.html", target:"navTab", rel:"articleAddEdit4"}, { id:4, pId:3, name:"弹出层", url:"articleAddEdit.html", target:"dialog", rel:"articleAddEdit5",mask:true,width:860,height:600}, { id:4, pId:3, name:"文章管理6", url:"articleAddEdit.html", target:"navTab", rel:"articleAddEdit6"} ]; $(document).ready(function(){ $.fn.zTree.init($("#treeDemo"), setting, zNodes); }); 如果要菜单不响应点击事件,请设置url:"#" 此代码处理了弹出层刷新及弹出层分页问题,这部分没有提供例子。 别怪我分数这么贵,真心的自己花了时间去测试改进,希望帮助到更多朋友。 有问题或建议请写评论或发信。
最初在CSDN上发了这份代码,整合了ztree3.3的核心部分,详情可以参看这个地址的说明: http://download.csdn.net/detail/ohaozy/8691959 据部分朋友的意见,需要使用ztree的excheck功能,于是我重新整合了ztree3.5,包括excheck,以及部分ztree美化图标。 因为CSDN上资源被下载过就不能更新及删除,只好重新发一份。推荐朋友们下载这份源代码,原先下载过的朋友可以留给我邮箱或者发邮件给我:[email protected],我单独发给你们。 压缩包是完整的jfinal+dwz的测试性小代码,直接导入myeclipse,运行DwzConfig.java,访问http://localhost:8888/admin就可以进入页面。 代码例子是JAVA的,dwz,ztree等是前台的东西,和后台没有关系。不管.net还是php都通用,请根据使用的平台,修改发布WebRoot下的文件,修改admin.jsp就可以。 ztree代码已经集成到dwz.min.js,不要再次单独引入js。 使用例子: var setting = { check: { enable: true,//只有这个属性就是checkbox chkStyle: "radio", radioType: "all"//level }, data: { simpleData: { enable: true } } }; /* 要是菜单不响应点击事件,请设置url:"#" */ var zNodes =[ { id:1, pId:0, name:"菜单管理(不响应点击)",iconSkin:"pIcon01", url:"#",open:false}, { id:2, pId:1, name:"菜单2(响应点击)", iconSkin:"pIcon02",url:"admin/articleAddEdit.html", target:"navTab", rel:"articleAddEdit2",open:false}, { id:3, pId:2, name:"菜单3(不响应点击)", iconSkin:"pIcon02",url:"#", target:"navTab", rel:"articleAddEdit3",open:false}, { id:4, pId:3, name:"文章管理4", iconSkin:"icon04",url:"admin/articleAddEdit.html", target:"navTab", rel:"articleAddEdit4"}, { id:5, pId:3, name:"弹出层", iconSkin:"icon04",url:"admin/articleAddEdit.html", target:"dialog", rel:"articleAddEdit5",mask:true,width:860,height:600}, { id:6, pId:3, name:"文章管理6", iconSkin:"icon04",url:"admin/articleAddEdit.html", target:"navTab", rel:"articleAddEdit6"}, { id:7, pId:1, name:"文章管理7", iconSkin:"pIcon02",url:"admin/articleAddEdit.html", target:"navTab", rel:"articleAddEdit7"}, { id:8, pId:7, name:"文章管理8", iconSkin:"pIcon02", url:"admin/articleAddEdit.html", target:"navTab", rel:"articleAddEdit8"}, { id:9, pId:8, name:"文章管理9", iconSkin:"icon04",url:"admin/articleAddEdit.html", target:"navTab", rel:"articleAddEdit9"} ]; $(document).ready(function(){ $.fn.zTree.init($("#treeDemo"), setting, zNodes); }); 有问题或建议请写评论或发信。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值