兼容iis服务器document root

This commit is contained in:
devil_gong 2019-04-09 11:54:32 +08:00
parent 94a9b2ba68
commit 784c9b93fa
3 changed files with 38 additions and 3 deletions

View File

@ -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)
);
}

View File

@ -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

View File

@ -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;