sowmithrii Posted December 3, 2007 Share Posted December 3, 2007 i dont understand the purpose of dirname(__FILE__) function. i created my sites folder MYSITE, and in that few subfolders FOLDER1 , FOLDER2, FOLDER3. I added few files to MYSITE folder like index.php, register.php, login.php... and so. and one file to all sub folders like... folder1.php, folder2.php, folder3.php as their names reflect. when i visit my site... http://MYSITE.com/MYSITE and if i have used dirname(__FILE__) in index.php, folder1.php, folder2.php, folder3.php And i have nagivation from index.php to folder1.php from there to folder2.php, from here to folder3.php what will be the result of dirname(__FILE__), when i am in index.php and in folder1.php, folder2.php, folder3.php , when each page prints that dirname(__FILE__) functions output. am new to php... please explain me clearly.. its a request. thanks and regards.. sowmithrii Link to comment https://forums.phpfreaks.com/topic/79948-dirname__file__-how-this-works/ Share on other sites More sharing options...
lur Posted December 3, 2007 Share Posted December 3, 2007 __FILE__ - The full path and filename of the file. If used inside an include, the name of the included file is returned. dirname - Given a string containing a path to a file, this function will return the name of the directory. Link to comment https://forums.phpfreaks.com/topic/79948-dirname__file__-how-this-works/#findComment-404940 Share on other sites More sharing options...
5ubliminal Posted December 3, 2007 Share Posted December 3, 2007 The dirname(__FILE__) trick is invaluable. Let's say you have a text file in the same folder as the include and you want the included file to load it. As you know PHP runs the included files as a pasted chunk of code but works on its current directory not the includes. This is where dirname(__FILE__) returns the actual folder of the include and you can load a file located in same folder for internal use. Hope it's clear Link to comment https://forums.phpfreaks.com/topic/79948-dirname__file__-how-this-works/#findComment-404943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.