Home  >  Article  >  php教程  >  PHP 中dirname(_file_)讲解

PHP 中dirname(_file_)讲解

WBOY
WBOYOriginal
2016-06-13 12:32:39834browse

通常在配置文件路径的时候用dirname(__FILE__)是非常有效的方法,但是因为__FILE__的路径是当前代码所在文件(而不是url所在文件)完整路径,所以定义配置文件通常要放在根目录下定义网站的根地址,但是下面的方法可以解决配置文件的存放问题。
dirname(dirname(__FILE__)); /* 
假设__FILE__为 /home/web/config/config.php  
上面的方法输出为 /home/web  
*/ 
dirname(dirname(__FILE__));得到的是文件上一层目录名
dirname(__FILE__);得到的是文件所在层目录名 

Statement:
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