Jump to content

how to get the name of the file including a file from the included file


efficacious

Recommended Posts

how to get the name of the file including a file from the included file,

 

This one has me mixed up a bit.. I am trying to record site activity information from a common.php file using a user object. But since the file is included into different php files based on different situations I need a dynamic way of finding the file name that is including it. I could be over complicating things but right now this seems like the best solution other wise I'll have to rewrite the code on every page i write. Is there a function for doing this? Or if someone gets what I'm trying to do if they could point me to the direction of some more information on it.

 

Thanks.

nvm i figured it out thanks neways all. 

 

If anyones curious

//Get the File name
$LongName = __FILE__;
$SplitName = explode("/", $LongName);
$CurrFile = $SplitName[count($SplitName) - 1];
echo($CurrFile);

nevermind i figured it out thanks neways all. 

 

If anyones curious

//Get the File name
$LongName = __FILE__;
$SplitName = explode("/", $LongName);
$CurrFile = $SplitName[count($SplitName) - 1];
echo($CurrFile);

 

Almost figured it out.. the __FILE__ constant wasn't updating each page change I'm not sure why but this seems to have fixed it.

 

Replaced:

$LongName = __FILE__;

 

With:

$LongName = $_SERVER["SCRIPT_NAME"];

 

__FILE__ will always return the name of the file it's residing in.

 

It says in the manual - The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.

__FILE__ will always return the name of the file it's residing in.

 

It says in the manual - The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.

 

ty you for the explanation xyph

Protip: basename.

 

doesn't that require me to already know the path of the file?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.