From 784c9b93faa1d52f2755a85f1071bbbb032924db Mon Sep 17 00:00:00 2001 From: devil_gong Date: Tue, 9 Apr 2019 11:54:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9iis=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8document=20root?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Ueditor.php | 5 ++-- application/common.php | 34 ++++++++++++++++++++++++ extend/base/Uploader.php | 2 +- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/application/admin/controller/Ueditor.php b/application/admin/controller/Ueditor.php index 85460bd80..7727765d8 100755 --- a/application/admin/controller/Ueditor.php +++ b/application/admin/controller/Ueditor.php @@ -275,7 +275,7 @@ class Ueditor extends Common $end = $start + $size; /* 获取文件列表 */ - $path = $_SERVER['DOCUMENT_ROOT'] . (substr($path, 0, 1) == "/" ? "":"/") . $path; + $path = GetDocumentRoot() . (substr($path, 0, 1) == "/" ? "":"/") . $path; $files = $this->GetFilesList($path, $allow_files); // 倒序 @@ -359,6 +359,7 @@ class Ueditor extends Common if(!is_dir($path)) return null; if(substr($path, strlen($path) - 1) != '/') $path .= '/'; $handle = opendir($path); + $document_root = GetDocumentRoot(); while(false !== ($file = readdir($handle))) { if($file != '.' && $file != '..') @@ -371,7 +372,7 @@ class Ueditor extends Common if(preg_match("/\.(".$allow_files.")$/i", $file)) { $files[] = array( - 'url'=> substr($path2, strlen($_SERVER['DOCUMENT_ROOT'])), + 'url'=> substr($path2, strlen($document_root)), 'mtime'=> filemtime($path2) ); } diff --git a/application/common.php b/application/common.php index 54c525843..2f7c747bf 100755 --- a/application/common.php +++ b/application/common.php @@ -11,6 +11,40 @@ // 应用公共文件 +/** + * 获取当前系统所在根路径 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2019-04-09 + * @desc description + */ +function GetDocumentRoot() +{ + // 当前所在的文档根目录 + if(!empty($_SERVER['DOCUMENT_ROOT'])) + { + return $_SERVER['DOCUMENT_ROOT']; + } + + // 处理iis服务器DOCUMENT_ROOT路径为空 + if(!empty($_SERVER['PHP_SELF'])) + { + // 当前执行程序的绝对路径及文件名 + if(!empty($_SERVER['SCRIPT_FILENAME'])) + { + return str_replace('\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0 -strlen($_SERVER['PHP_SELF']))); + } + + // 当前所在绝对路径 + if(!empty($_SERVER['PATH_TRANSLATED'])) + { + return str_replace('\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0 -strlen($_SERVER['PHP_SELF']))); + } + } + return ''; +} + /** * 生成随机字符串 * @author Devil diff --git a/extend/base/Uploader.php b/extend/base/Uploader.php index f46584319..606916b19 100755 --- a/extend/base/Uploader.php +++ b/extend/base/Uploader.php @@ -453,7 +453,7 @@ class Uploader private function getFilePath() { $fullname = $this->fullName; - $rootPath = $_SERVER['DOCUMENT_ROOT']; + $rootPath = GetDocumentRoot(); if (substr($fullname, 0, 1) != '/') { $fullname = '/' . $fullname;