当前位置:网站首页>PHP gets the website root directory, and several methods for PHP to get the website root directory
PHP gets the website root directory, and several methods for PHP to get the website root directory
2022-07-21 05:33:00 【u011042325】
stay php We want to get the website root directory You can use many global variables to realize , If you can use __file__ or DOCUMENT_ROOT Wait for variables to get , Let's take a look at some examples .
__file__
dirname(__file__) // What we got was this Soft connection Absolute directory of itself
If you want to execute in soft connection php The way to get the root directory of the website from the file is :
$dir = $_SERVER['DOCUMENT_ROOT'] ; //# Get the root directory of the document where the script is currently running .
php Get the website root directory method 1 :
define("WWWROOT",str_ireplace(str_replace("/","\\",$_SERVER['PHP_SELF']),'',__FILE__)."\\");
echo WWWROOT ;
?>
php Method 2 of obtaining website root directory :
define('WWW_PATH',str_replace('\\','/',realpath(dirname(__FILE__).'/../'))); // Define Site Directory
?>
php Method 3 to get the root directory of the website :
$_SERVER['DOCUMENT_ROOT'] // The root directory of the document where the script is currently running . Define... In the server configuration file
Other ways to get directories :
$_SERVER['SCRIPT_FILENAME'] # The absolute pathname of the currently executing script .
$_SERVER['PATH_TRANSLATED'] # The file system of the current script ( Not the document root ) Basic path .
$_SERVER['SCRIPT_NAME'] # Contains the path of the current script . This is useful when the page needs to point to itself .
Related resources :php Several methods to obtain the physical path of the website root directory ( recommend )_php Get root directory path ...
边栏推荐
- VOD constructs its own player, and the user calls the interface to obtain the video playback address
- Go atomic operation
- Rmarkdown与Word文档的交互
- 经典网络学习-ResNet代码实现
- Webdynpro development-03 create a Webdynpro material code query page
- tp5.1 include 包含文件(引用公共文件)
- Duplicate class com.amap.api.fence.DistrictItem found in modules jetified-3dmap-9.3.1.jar (com.amap.
- 阿里云 cdn 域名的配置方法
- R language homework III
- 6.0 error saving UnionPay parameters: unable to open file
猜你喜欢
你了解实时3D渲染吗?实时渲染软件和应用场景科普来了
Iptables firewall experiment
Go GMP model
【C】文件操作进阶知识
TP5.1 登录 配置是否登录公共函数的方法(完整的登录案例)
6.0 取消会员注册验证码
Common classes under JUC package
宝塔 workerman wss 反向代理 socket合法域名 小程序聊天 去掉端口
[hbuilder runs to the problem that Mumu simulator cannot install the base, and it has been stuck in the installation base...]
Request和Response
随机推荐
R语言求 凹凸区间及拐点
CTFShow-MISC入门篇
R语言 | 向量化操作purrr包
宝塔 workerman wss 反向代理 socket合法域名 小程序聊天 去掉端口
Drawing multi group Y-axis truncation graph with R language
Getting started with microservices
Console C # flying chess small project
阿里云 cdn 域名的配置方法
Detailed explanation of x509 digital certificate
[C language brush leetcode] 729 My schedule I (m)
Php obtient le Répertoire racine du site Web, plusieurs méthodes PHP obtient le Répertoire racine du site Web
tp5.1 include 包含文件(引用公共文件)
flv封装解析
Go atomic operation
ASP.NET Core使用记录3
tp5.1 控制器初始化initialize(继承公共文件初始化)
tp5.0 后台admin访问
几个DPDK控制框架
利用yaml定义卷积网络【附代码】
Location unavailable - file or directory is corrupt and unreadable