自留地
切勿乱来!
     找回密码

PHPCMS V9 修改flash上传为H5上传方案

#PHPCMS专题

默认phpcms v9上传用到flash,但现在每天打开谷歌浏览器,都得手动去设置flash这块,真的很麻烦!

到2020年,微软和谷歌宣布各自的浏览器将彻底不再支持,那怎么办,似乎能替代的方案只有H5上传(html5上传);

为此phpcms剔除flash上传势在必行,不然到时候连个基础上传功能都将无法使用,修改效果见下图:

上传窗口

选择图片

上传成功后,便可插入编辑器

未使用图片提示状态

本H5上传采用开源项目webuploader,webuploader介绍:WebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现代文件上传组件。在现代的浏览器里面能充分发挥HTML5的优势,同时又不摒弃主流IE浏览器,沿用原来的FLASH运行时,兼容IE6+,iOS 6+, android 4+。两套运行时,同样的调用方式,可供用户任意选用。

采用大文件分片并发上传,极大的提高了文件上传效率。

webuploader官网:http://fex.baidu.com/webuploader/

有需要的,联系QQ:6045564,好友验证写明H5上传

默认V9没有做修改的,请直接上传压缩包覆盖。以下为手动修改教程:

第一步,修改:/phpcms/modules/attachment/attachments.php 修改public function swfupload(){方法

 /**
   * swfupload上传附件(已改)
   * web uploader上传
   */
  public function swfupload(){
    $grouplist = getcache('grouplist','member');
                <span class="k">if</span><span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">isadmin</span><span class="o">==</span><span class="mi">1</span><span class="p">)</span> <span class="nb">define</span><span class="p">(</span><span class="s1">'IN_ADMIN'</span><span class="p">,</span><span class="kc">true</span><span class="p">);</span>
    $siteid = $this->get_siteid();
    if(isset($_GET['dosubmit'])){
      pc_base::load_sys_class('attachment','',0);
      $attachment = new attachment($_POST['module'],$_POST['catid'],$siteid);
      $attachment->set_userid($_POST['userid']);
      $site_setting = get_site_setting($siteid);
      $site_allowext = $site_setting['upload_allowext'];
      $aids = $attachment->upload('file',$site_allowext,0,0,array(intval($_POST['thumb_width']),intval($_POST['thumb_height'])),intval($_POST['watermark_enable']));
      if($aids[0]) {
        $filename= (strtolower(CHARSET) != 'utf-8') ? iconv('gbk', 'utf-8', $attachment->uploadedfiles[0]['filename']) : $attachment->uploadedfiles[0]['filename'];
        if($attachment->uploadedfiles[0]['isimage']) {
          $res = array(
            'status' => 1,
            'aid' =>  $aids[0],
            'filepath' => $this->upload_url.$attachment->uploadedfiles[0]['filepath'],
            'fileext' => $attachment->uploadedfiles[0]['fileext'],
            'isimage' => $attachment->uploadedfiles[0]['isimage'],
            'title'   => str_replace('.'.$attachment->uploadedfiles[0]['fileext'],'',$filename),
            'fileimg' => $this->upload_url.$attachment->uploadedfiles[0]['filepath'],
            'filename' => $filename
          );
          echo json_encode($res);
        } else {
          $fileext = $attachment->uploadedfiles[0]['fileext'];
          if($fileext == 'zip' || $fileext == 'rar') $fileext = 'rar';
          elseif($fileext == 'doc' || $fileext == 'docx') $fileext = 'doc';
          elseif($fileext == 'xls' || $fileext == 'xlsx') $fileext = 'xls';
          elseif($fileext == 'ppt' || $fileext == 'pptx') $fileext = 'ppt';
          elseif ($fileext == 'flv' || $fileext == 'swf' || $fileext == 'rm' || $fileext == 'rmvb') $fileext = 'flv';
          else $fileext = 'do';
          $res = array(
            'status' => 1,
            'aid' =>  $aids[0],
            'filepath' => $this->upload_url.$attachment->uploadedfiles[0]['filepath'],
            'fileext' => $fileext,
            'isimage' => $attachment->uploadedfiles[0]['isimage'],
            'title'   => str_replace('.'.$attachment->uploadedfiles[0]['fileext'],'',$filename),
            'fileimg' => file_icon($this->upload_url.$attachment->uploadedfiles[0]['filepath']),
            'filename' => $filename
          );
          echo json_encode($res);
        }     
        exit;
      } else {
        echo '0,'.$attachment->error();
        exit;
      }
    } else {
      if($this->isadmin==0 && !$grouplist[$this->groupid]['allowattachment']) showmessage(L('att_no_permission'));
      $args = $_GET['args'];
      $authkey = $_GET['authkey'];
      $type = $_GET['type'];
      if(upload_key($args) != $authkey) showmessage(L('attachment_parameter_error'));
      extract(getswfinit($_GET['args']));
      $siteid = $this->get_siteid();
      $site_setting = get_site_setting($siteid);
      $file_size_limit = sizecount($site_setting['upload_maxsize']*1024); 
      $filetype = str_replace('|',',',$file_types_post);
      $att_not_used = param::get_cookie('att_json');
      if(empty($att_not_used) || !isset($att_not_used)) $tab_status = ' class="on"';
      if(!empty($att_not_used)) $div_status = ' hidden';
      //获取临时未处理文件列表
      $att = $this->att_not_used();
      $userid_flash=sys_auth($this->userid, 'ENCODE');
      // include $this->admin_tpl('swfupload');
      include $this->admin_tpl('webuploader');
    }
  }

 

第二步:压缩包里,除了/phpcms/modules/attachment/attachments.php 不覆盖,其余全部上传,该压缩包结构如下:

phpcms目录,里面除了不覆盖的那文件外,还有一个webuploader.tpl.php 为上传使用的模板文件,不会重复

statics目录,里面为webuploader上传组件,直接上传

修改完毕,进入后台更新栏目缓存,清理浏览器缓存即可

特别需求类解决:偶遇有部分用户站点绑定的是多个域名,而且服务器没开启跨域功能,造成无法上传,上传原因是跨域拦截。修改方式如下:

/modules/attachment/templates/webuploader.tpl.php

这个文件的101行,里面的APP_PATH给去掉

2021.11.18更新:现存版本都存在重大漏洞,已购买用户抓紧更新!

1 赞 收藏 打赏
×
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《PHPCMS V9 修改flash上传为H5上传方案》
文章链接:https://www.ediok.cn/blog/2019/10/1114.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
分享到

评论 2

评论前必须登录!

 

  1. #1
    用户头像

    安装说明来搞 不行呀

    ghost 广东省6年前 (2020-10-01) 赞
    • 用户头像

      联系我可以为你排查原因,QQ:6045564

      周涛6年前 (2020-10-01) 赞

关注互联网发展前沿,关注PHPCMS技术演进,钻研PHPCMS技术开发

问答社区 联系我们

登录

登录即表示同意本站用户协议、隐私政策
©2026 周涛博客 All rights reserved

注册

注册即表示同意本站用户协议、隐私政策
©2026 周涛博客 All rights reserved

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

微信扫一扫

微信扫一扫