Home > Backend Development > PHP Tutorial > Several ways to obtain the physical path of the website root directory in php

Several ways to obtain the physical path of the website root directory in php

不言
Release: 2023-03-29 12:28:02
Original
7376 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获取表单数据与HTML嵌入PHP脚本的实现

PHP中子类重载父类的方法(parent::方法名)

The above is the detailed content of Several ways to obtain the physical path of the website root directory in php. For more information, please follow other related articles on the PHP Chinese website!

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