PDA

View Full Version : How to get the filename in PHP


Steven
December 29th, 2007, 15:58
Hello,

I'm trying to display the last updated time of a particular file in my footer.

The way I have designed my pages, is I have one footer.php file that is called by all the other pages.

Now in the footer file, I want to display the update time, with this code:

echo date("m/d/Y", filemtime(“test.php”));

So what I want to do, is instead of calling 'test.php,' I will put a variable that will automatically detect the current page, and display the relevant value.

Any ideas of how I can do this?

Thanks a mil!

Gerrit
December 29th, 2007, 16:30
In every file I have in the first line something like: <?php $thisPage = "foo.php"; ?>

I use it for - among other things - detecting the current page for the included site navigation. It would work for your footer too :)

Steven
December 29th, 2007, 17:01
o wow... nice trick! :)

Thanks man ;)

Dan
December 30th, 2007, 01:32
http://us2.php.net/manual/en/reserved.variables.php#reserved.variables.server

There are a few different ways to get the filename using $_SERVER.

If you create a phpinfo file with just <?php phpinfo(); ?> it will print out a handful of $_SERVER keys and their associated values, which is a little bit easier to comprehend than PHP.net's manual.