Heim  >  Artikel  >  Backend-Entwicklung  >  ftisland hello hello PHP 得到根目录的 __FILE__ 常量

ftisland hello hello PHP 得到根目录的 __FILE__ 常量

WBOY
WBOYOriginal
2016-07-29 08:38:25863Durchsuche

1。PHP 的 __FILE__ 常量(如何得到根目录)
dirname(__FILE___) 函数返回的是脚本所在在的路径。
比如文件 b.php 包含如下内容:
$basedir = dirname(__FILE__);
?>
如果b.php被其他目录里的a.php文件require 或者 include 去引用的话。
变量$basedir 的内容还是b.php所在的那个文件夹的路径。
而不是变成a.php文件所在的目录。
dirname(__FILE__) 一般会返回文件所的当前目录到系统根目录的一个目录结构。
不会返回当前的文件名称。
dirname(__FILE__) 也可能返回一个 . (当前目录)
[原因是 b.php 文件在 http.conf 或者 PHP 配置开发环境的默认WEB目录下.
比如 WEB_ROOT 为: "C:/root/www/".]
b.php文件路径为: "C:/root/www/b.php". 使用方法提示, 如果重复一次可以把目录往上提升一个层次:
比如:$d = dirname(dirname(__FILE__));
其实就是把一个目录给dirname()做参数了.因为dirname()返回最后的目录不带\\或者是/
所以重复使用的时候可以认为 dirname() 把最下层的目录当成文件名来处理了.照常返回
当前目录的上级目录.这样重复就得到了它的上一级的目录. 包含得到上一级目录的文件include(dirname(__FILE__).'/../filename.php');2。如何将PHP文件和html文件结合使用 if($reguser != ""){
  echo"Submit Photo
";
  echo"Log Out";
}else{
  echo"Login";
}
?> 

以上就介绍了ftisland hello hello PHP 得到根目录的 __FILE__ 常量,包括了ftisland hello hello方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn