zoukankan      html  css  js  c++  java
  • 在使用openbms的时候发现的Thinkphp action 大小写问题

    下载了 https://gitee.com/openbms/openbms 看了看源代码,调试了一下普通用户的demo 用户 发现无法上传图片,admin不会,查看了源代码 发现是这样的

    admin用户因为是管理员直接跳过权限检查了 代码在 application/common/controller/AdminBase.php

     普通用户到 

    !in_array($this->request->action(), $this->noAuth)

    检查失败 然后看了一下请求 

    /admin/index/uploadImage

    请求地址和内容没问题 调试了一下代码 发现 当前action 和noAuth分别为

    string(11) "uploadimage"
    array(6) {
      [0]=>
      string(5) "index"
      [1]=>
      string(11) "uploadImage"
      [2]=>
      string(10) "uploadFile"
      [3]=>
      string(11) "uploadVideo"
      [4]=>
      string(8) "iconLibs"
      [5]=>
      string(6) "logout"
    }

    发现问题所在  request 得到的 action 被转了小写,没有驼峰法了,然后发现有人也遇到类似的问题  https://blog.csdn.net/weixin_30797199/article/details/96202967

     然后就只要改一下这里就行了

     其他几个上传 file 上传 video的同理。

    不过这里的问题是TP核心对action 的处理的问题 我觉得可以把这里的action 请求都强制转小写 然后在判断,可以兼容两个版本。例如

     patch 如下

    diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php
    index 3c2baac..cbb6f39 100644
    --- a/application/admin/controller/Index.php
    +++ b/application/admin/controller/Index.php
    @@ -12,10 +12,10 @@ class Index extends AdminBase
         ];
         protected $noAuth = [
             'index',
    -        'uploadImage',
    -        'uploadFile',
    -        'uploadVideo',
    -        'iconLibs',
    +        'uploadimage',
    +        'uploadfile',
    +        'uploadvideo',
    +        'iconlibs',
             'logout'
         ];
    
    
    diff --git a/application/common/controller/AdminBase.php b/application/common/controller/AdminBase.php
    index 941adb6..ad3fc5e 100644
    --- a/application/common/controller/AdminBase.php
    +++ b/application/common/controller/AdminBase.php
    @@ -33,8 +33,8 @@ class AdminBase extends Base
         public function checkAuth()
         {
             if (session('admin_auth.username') != config('administrator') &&
    -            !in_array($this->request->action(), $this->noLogin) &&
    -            !in_array($this->request->action(), $this->noAuth) &&
    +            !in_array(strtolower($this->request->action()), $this->noLogin) &&
    +            !in_array(strtolower($this->request->action()), $this->noAuth) &&
                 !(new coreAuth())->check($this->request->module() . '/'
                     . to_under_score($this->request->controller()) . '/'
                     . $this->request->action(), session('admin_auth.admin_id'))) {

    这里改好了就能上传了

  • 相关阅读:
    Emacs 安装 jedi
    PHP+ MongoDB
    Debian 7 安装 Emacs 24.3
    在Code first中使用数据库里的视图
    Emacs安装auto-complete
    Debian 7.4 中配置PHP环境
    ASP.NET MVC 下载列表
    JDicom使用指南
    Windows常用的DOS命令
    Entity Framework问题总结
  • 原文地址:https://www.cnblogs.com/lizhaoyao/p/14639055.html
Copyright © 2011-2022 走看看