在PHP中获取webroot [英] Get webroot in PHP

查看:304
本文介绍了在PHP中获取webroot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Apache服务器用于 PHP .如何在PHP中检索http://localhost/testthesis/之类的Web根目录?

I am using Apache server for PHP. How can I retrieve my web root in PHP, like http://localhost/testthesis/?

推荐答案

相对路径

对于您的Web服务器的根目录,请使用:

Relative paths

For your webservers root directory, use:

$folder = '/';

对于检索到的脚本的目录,请使用:

For the directory of the retrieved script, use:

$folder = './';

绝对路径(从客户的角度来看)

对于您的Web服务器的根目录,请使用:

Absolute paths (from the client's perspective)

For your webservers root directory, use:

$protocol = $_SERVER['HTTPS'] == '' ? 'http://' : 'https://';
$folder = $protocol . $_SERVER['HTTP_HOST'];

对于检索到的脚本的目录,请使用:

For the directory of the retrieved script, use:

$protocol = $_SERVER['HTTPS'] == '' ? 'http://' : 'https://';
$folder = $protocol . $_SERVER['HTTP_HOST'] . '/' . basename($_SERVER['REQUEST_URI']);

这篇关于在PHP中获取webroot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆