首页 > Web开发 > 详细

在使用openbms的时候发现的Thinkphp action 大小写问题

时间:2021-04-10 00:52:19      阅读:25      评论:0      收藏:0      [点我收藏+]

下载了 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 \core\Auth())->check($this->request->module() . /
                 . to_under_score($this->request->controller()) . /
                 . $this->request->action(), session(admin_auth.admin_id))) {

这里改好了就能上传了

在使用openbms的时候发现的Thinkphp action 大小写问题

原文:https://www.cnblogs.com/lizhaoyao/p/14639055.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!