first:
php中常用的路徑
當(dāng)前文件路徑:D:\phpweb\php_example\include_path.php
復(fù)制代碼 代碼如下:
1.dirname(__FILE__); //輸出D:\phpweb\php_example
2.$_SERVER['SCRIPT_FILENAME']; //輸出D:/phpweb/php_example/include_path.php
second:
php中的set_include_path
在php中,include文件時,當(dāng)包含路徑不為相對也不為絕對時(如:include("example.php")),會先查找include_path所設(shè)置的目錄,然后再在當(dāng)前目錄查找,這也是為什么很多資料上提到include("./example.php")比include("example.php")效率高的原因。
方法:
1.ini_set("include_path", "/usr/lib/pear"); //所有版本
2.set_include_path("/usr/lib/pear"); //version>=4.3.0
可以用下面的方法,在原有目錄上添加目錄
復(fù)制代碼 代碼如下:
<?php
$path = '/usr/lib/pear';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);//設(shè)置后的include_path變?yōu)轭愃?usr/lib/function;/usr/lib/pear
?>