How can I get the name of a file in in PHP? What I want to do is have a function take a string of a filename and then do some stuff if it's actually on the page.
function onThisPageFunction(fileNameFromFunction)
{
if(onThisPage == fileNameFromFunction)
{
do stuff
}
}
There are two variables that will give you file names.
eg: you call /test/test1.php as the url and test1.php includes test2.php.
__FILE__ will give you the current file of the executing code, in this case it will return "test2.php"
$_SERVER['PHP_SELF'] will give you the full url of the original call, in this case "/test/test1.php"
Note that you can use the basename() function to get just the filename from a path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With