Home > Backend Development > PHP Tutorial > Several methods (recommended) techniques for obtaining the physical path of the website root directory in PHP

Several methods (recommended) techniques for obtaining the physical path of the website root directory in PHP

黄舟
Release: 2023-03-06 11:34:02
Original
2712 people have browsed it

下面小编就为大家带来一篇php获取网站根目录物理路径的几种方法(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

在PHP中获取网站根目录物理路径。

在php程序开发中经常需要获取当前网站的目录,我们可以通过常量定义获取站点根目录物理路径,方便在程序中使用。

下面介绍几种常用的获取网站根目录的方法。

php获取网站根目录方法一:

<?php
define("WWWROOT",str_ireplace(str_replace("/","\\",$_SERVER[&#39;PHP_SELF&#39;]),&#39;&#39;,__FILE__)."\\");
echo WWWROOT ;
?>
Copy after login

php获取网站根目录方法二:

<?php
define(&#39;WWW_PATH&#39;,str_replace(&#39;\\&#39;,&#39;/&#39;,realpath(dirname(__FILE__).&#39;/../&#39;))); //定义站点目录
?>
Copy after login

php获取网站根目录方法三:

$_SERVER['DOCUMENT_ROOT'] //当前运行脚本所在的文档根目录。在服务器配置文件中定义。

以上就是php获取网站根目录物理路径的几种方法(推荐)技巧的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template