[英]Get root url of disk PHP
How can I get the root of the disk on my server?如何获取服务器上磁盘的根目录? Like for example in windows I would like to get into the root of the drive
C:/
but I want my code to be dynamic if we ever decide to use linux.例如在 windows 中,我想进入驱动器
C:/
但如果我们决定使用 linux,我希望我的代码是动态的。
I have tried $_SERVER['DOCUMENT_ROOT']
but it only returns the root folder of the project.我试过
$_SERVER['DOCUMENT_ROOT']
但它只返回项目的根文件夹。
Is there any way to do this in PHP?在 PHP 中有没有办法做到这一点?
You don't need to manually construct that / worry about it.您无需手动构建/担心它。
A better approach is to have a constant in your project that marks the path to it from the root.更好的方法是在项目中使用一个常量来标记从根到它的路径。
To do this you can do something like为此,您可以执行以下操作
define('PROJECT_ROOT', __DIR__);
See more about __DIR__
here: https://www.php.net/manual/en/language.constants.predefined.php在此处查看有关
__DIR__
的更多信息: https://www.php.net/manual/en/language.constants.predefined.php
Basically this takes care of the OS context for you so if your project is on windows it'll be C:\...
and on Linux based systems just /...
基本上这会为您处理操作系统上下文,因此如果您的项目在 windows 上,它将是
C:\...
并且在 Linux 系统上只是/...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.