Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileService::getBaseUriLocal() 返回的路径不对 #47

Closed
Jamling opened this issue Sep 9, 2017 · 5 comments
Closed

FileService::getBaseUriLocal() 返回的路径不对 #47

Jamling opened this issue Sep 9, 2017 · 5 comments

Comments

@Jamling
Copy link

Jamling commented Sep 9, 2017

缺少了 Think.Admin (${root})

        dump($this->request->root(true));
        dump(FileService::getBaseUriLocal());

结果为

string(33) "http://192.168.133.15/Think.Admin"
string(36) "http://192.168.133.15/static/upload/"

@zoujingli
Copy link
Owner

zoujingli commented Sep 12, 2017

 /**
     * 获取服务器URL前缀
     * @return string
     */
    public static function getBaseUriLocal()
    {
        $request = request();
        $base = $request->root();
        $root = strpos($base, '.') ? ltrim(dirname($base), DS) : $base;
        if ('' != $root) {
            $root = '/' . ltrim($root, '/');
        }
        return ($request->isSsl() ? 'https' : 'http') . '://' . $request->host() . "{$root}/static/upload/";
    }

我当前环境测试是正常的

@Jamling
Copy link
Author

Jamling commented Sep 13, 2017

如果部署的文件夹带. 如Think.Admin。将会执行ltrim(dirname($base), DS)。导致root为空。然后就少了Think.Admin这一级。

@zoujingli
Copy link
Owner

    /**
     * 获取服务器URL前缀
     * @return string
     */
    public static function getBaseUriLocal()
    {
        $appRoot = request()->root(true);
        $uriRoot = preg_match('/\.php$/', $appRoot) ? dirname($appRoot) : $appRoot;
        return "{$uriRoot}/static/upload/";
    }

你看这样,可以解决你的问题不?

@zoujingli zoujingli reopened this Sep 13, 2017
@zoujingli
Copy link
Owner

相关代码已经更新!

@Jamling
Copy link
Author

Jamling commented Sep 13, 2017

可以的,我自己修改的代码是使用 TP的request->root(true)来生成的。不过,上传那部分调用了FileService。偶然发现的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants