Getting path name of included script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

Getting path name of included script

Post by bradles »

I have a script that will be included on an index page but I need to get the name of the path that the particular script resides in. $_SERVER['PHP_SELF'] will give me the path name of the index.php script but the included script resides in another folder.

Any ideas about how to get that pathname? I've searched high & low and can't seem to find anything on it.

Brad
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

__FILE__
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

Post by bradles »

__FILE__
Thanks feyd, but that returns a drive path. I'm trying to get the server path to the included script because that script will be loading images. Please don't think that I don't appreciate your help. Most of what I've achieved with this project has been through your help.

Image gallery script is in /www/weddings/
thumbnails are in /www/weddings/thumbnails/
Index script is in /www/

When the index script runs it includes the gallery script. As an example, on that script I need to show:

Code: Select all

"<img src="WWW/WEDDINGS/THUMBNAILS/IMAGE/><br>\n";
I'm wondering if I should just make it a setting that the user can change in the script rather than trying to do it dynamically.

It'd be nice if i had something that returns only the name of the current folder of the included file. i.e, \weddings rather than the whole path.

Brad
jakobdoppler
Forum Commoner
Posts: 46
Joined: Wed May 21, 2003 6:16 pm

Post by jakobdoppler »

this is not tested , but it works somehow like this

Code: Select all

&lt;?php
&lt;?php
//to get the directory name (e.g) /www/weddings/ 
   $path = dirname(__FILE__);   
// to get the last subdirname "weddings"
   $path = substr(strrchr($path,"/"), 1 );   
?&gt;
?&gt;
*hth* _yak
Post Reply