LoginSignup
8
11

More than 5 years have passed since last update.

PHPのパス指定はなんとめんどくさいものなのだろうか

Posted at

絶対パス

サーバルートを基準にするため、環境の変化をもろに受けるのが特徴

include('/path/example.php');

個人的にあんまり使いたくない…

相対パス

最終的に実行するファイルからの相対パスを指定する。

include('../path/example.php');

あるphpから別のphpを読み込んでさらにまた…っとやっていくとカオスなことになるのでオススメしない

もう一つの相対パス?

下記のように./../をつけずに書いた相対パスはphp.iniinclude_pathで設定したディレクトリ下のpathディレクトリから探すらしいです。

include('path/example.php');

結局

安定して使うならこれかなー

include(__DIR__.'/path/example.php');
8
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
11