[5.1.14]更改入口,无法加载think\Image

浏览:1210 发布日期:2018/05/25 分类:求助交流
我项目目录结构:- tp51
- - thinkphp
- - vendor 
- - application 等文件夹
- public
- - index.php 入口文件
index.phpnamespace think;

// 定义应用目录
define('APP_PATH', __DIR__ . '/../tp51/application');

// 加载基础文件
require __DIR__ . '/../tp51/thinkphp/base.php';

// 支持事先使用静态方法设置Request对象和Config对象

// 执行应用并响应
Container::get('app', [APP_PATH])->run()->send();
//Container::get('app')->path(APP_PATH)->run()->send(); //这样会报错
问题:// think\Image等用composer安装的库无法加载
// Class 'think\Image' not found
$image = \think\Image::open('../uploads/demo.jpg');
经过测试,查找源代码发现:tp计算根路径方式有问题// 获取应用根目录 thinkphp\library\think\Loader.php
    public static function getRootPath()
    {
        if ('cli' == PHP_SAPI) {
            $scriptName = realpath($_SERVER['argv'][0]);
        } else {
            $scriptName = $_SERVER['SCRIPT_FILENAME'];
        }

        $path = realpath(dirname($scriptName));

        if (!is_file($path . DIRECTORY_SEPARATOR . 'think')) {
            $path = dirname($path);
        }

        return $path . DIRECTORY_SEPARATOR;
    }
常量还是有用的。
最佳答案
评论( 相关
后面还有条评论,点击查看>>