realpath(__DIR__)

パス

 閲覧数:1451  投稿日:2017-02-18  更新日:2017-02-18  

下記は同義
realpath(__DIR__)
realpath( dirname( __FILE__ ) )

--------------------------------------------------
realpath(__DIR__)
・PHP5.3.0以降

realpath( dirname( __FILE__ ) )
・PHP5.3.0未満

--------------------------------------------------
記述例
require(realpath(__DIR__).'/vendor/Psr4AutoloaderClass.php');


コード

//同階層
include(realpath(__DIR__).'/hoge.php');

//一つ上の階層
include(realpath(__DIR__).'/../hoge.php');

//二つ上の階層
include(realpath(__DIR__).'/../../hoge.php');

//内部で下記のように絶対パスへ自動変換される
include('/var/www/phpcode.w4c.work/demo/hoge.php');



include_pathを二箇所設定

現在WebページのURLパスを第2階層まで取得