php中dirname()和--FILE--常量的用法
__FILE__表示當前所在文件的絕對路徑包括文件名,dirname(__FILE__)表示當前文件的絕對路徑,basename(__FILE__)表示當前文件的文件名稱,dirname(__FILE__)."/f/"name(__FILE__)則表示當前文件所在目錄下的f目錄下的,文件名稱爲dirname(__FILE__)的文件,require表示包含該文件到這個文件。
下面是詳解:
1)dirname(__FILE___) 函數返回的是腳本所在在的路徑。
比如文件 包含如下內容:
<?PHP
$basedir = dirname(__FILE__);
?>
如果被其他目錄裏的文件require 或者 include 去引用的話。
變量$basedir 的內容還是所在的那個文件夾的路徑。
而不是變成文件所在的目錄。
2)dirname(__FILE__) 一般會返回文件所的當前目錄到系統根目錄的一個目錄結構。
不會返回當前的文件名稱。
dirname(__FILE__) 也可能返回一個 . (當前目錄)
[原因是 文件在 或者 PHP 配置開發環境的.默認WEB目錄下.
比如 WEB_ROOT 爲: "C:/root/www/".]
文件路徑爲: "C:/root/www/".
3)使用方法提示,
如果重複一次可以把目錄往上提升一個層次:
比如:$d = dirname(dirname(__FILE__));
其實就是把一個目錄給dirname()做參數了.因爲dirname()返回最後的目錄不帶\\或者是/
所以重複使用的時候可以認爲dirname()把最下層的目錄當成文件名來處理了.照常返回
當前目錄的上級目錄.這樣重複就得到了它的上一級的目錄.
4)包含得到上一級目錄的文件
include(dirname(__FILE__).'/../filename
相關文章
-
解決PHP的failed opening required問題的方法
人要想學習一點東西,就應該先學會謙遜。以下是小編爲大家搜索整理的解決PHP的failed opening required問題的方法,希望對大家有所幫助!更多精彩內容請及時關注我們應屆畢業生考試網!環境:WIN2003+IIS6+PHP5本機,2003下IIS -
高中英語作文:My approach to difficulties in learning
某校英文報社開設了一個專欄:experience . 本期話題是如何解決學習中遇到的`困難。請你以“my approach to difficulties in leaing” 爲題,用英語寫一篇短文,談談自己的一些做法。 範文: My approach to difficulties -
Different People Like Different Movies國中英語作文
Different people like different movies. Mary likes comedies, she thinks they are funny. She likes documentaries too, because she thinks documentaries are exciting . She doesn’t like thrillers. She th -
Jolie drops battle over perfume named Shilohy英語作文
angelina jolie has dropped her legal battle with a perfume-maker who had named her fragrance shiloh - the same as jolies youngest daughter.jolie had filed a note with the u.s. patent and trademark off -
Diaspora Finance Powers Global Development美文欣賞
Diaspora Finance Powers Global DevelopmentLuis Lopez-Ramirez, a 30-year old Honduran immigrant, makes pizza.He has worked two jobs over 16 hours each day.He carefully saves his money and rents a small -
英語閱讀範文參考:LovePeopleInAllKindsOfWeather
LovePeopleInAllKindsOfWeatherMake sure your love is unconditional. Make sure you love people in all kinds of "weather". Or else what is the use if we love a person only when he is good or she is nice? -
The place of Science and Technology in Modern Life英語作文
human life can not continue without science and technology. for many years, human society has developed with the advance of science and technology while the development of science and technology has i -
Zend studio for eclipse中使php可以調用mysql相關函數的設置方
Zend studio for eclipse中使php可以調用mysql相關函數的設置方法教程如果直接調用mysql_connect會出現:Fatal error: Call to undefined function mysql_connect() 的錯誤解決辦法,找到zend studio 所在的`位置我的zen -
解決PHP中的Cannot modify header information 問題
我就遇到這種問題,網上找到這個解決的方案,就收藏下寫PHP的朋友們肯定遇到過這樣一個問題:通過header函數改變http協議頭的時候,會出現一個類似下面格式的waing:複製代碼 代碼如下:Waing: Cannot modify header informatio -
英語演講稿《 I Am Tripping My Elephant Here》
once upon a time, a weenie ant was walking on his way. as he was walking, suddenly he felt the ground shaking terribly. he looked around with his paranoid eyes and saw an elephant walking right behind