Heim  >  Artikel  >  Backend-Entwicklung  >  PHP路径相关 dirname,realpath,__FILE__,dirnamerealpath_PHP教程

PHP路径相关 dirname,realpath,__FILE__,dirnamerealpath_PHP教程

WBOY
WBOYOriginal
2016-07-12 08:57:28753Durchsuche

PHP路径相关 dirname,realpath,__FILE__,dirnamerealpath

​比如:程序根目录在:E:\wamp\www 中

 

1.    __FILE__   当前文件的绝对路径

如果在index.php中调用 则返回  E:\wamp\www\index.php

 

下面再看一下 程序根目录的目录结构

 

 

如果在 c_system_base.php中调用__FILE__ 则返回:

E:\wamp\www\zb_system\function\c_system_base.php

 

2.dirname    返回当前目录的上级目录 或当前文件所在的目录 (结尾不带/)

一般跟__FILE__联合使用

 

如果在 c_system_base.php中调用dirname(__FILE__) 则返回 

E:\wamp\www\zb_system\function    (文说件返回所在目录)

如果调用 dirname(dirname(__FILE__)) 则返回  

E:\wamp\www\zb_system        (目录返回上级目录)

 

realpath()    方法 返回当前文件的绝对路径 或 相对根目录的路径

如果在 c_system_base.php中调用realpath(__FILE__) 则返回

E:\wamp\www\zb_system\function\c_system_base.php

 

realpath('/')    返回磁盘根目录    E:\

realpath('./')    返回根目录  E:\wamp\www

realpath('../')    返回相对程序根目录的上级目录

也可以和dirname配合使用 一般还会加上几个相对路径../ (前面要加/  即:/../)

realpath(dirname(__FILE__))    返回  E:\wamp\www\zb_system\function

realpath(dirname(__FILE__).'/../')  返回 E:\wamp\www\zb_system

realpath(dirname(__FILE__).'/../../')    返回    E:\wamp\www

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1108336.htmlTechArticlePHP路径相关 dirname,realpath,__FILE__,dirnamerealpath ​比如:程序根目录在:E:\wamp\www 中 1.__FILE__ 当前文件的绝对路径 如果在index.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