View Full Version : which path for filemtime to check whole directory?

07-31-2007, 08:38 PM

I'm using this code to display the last time any page of my site was updated:

echo "Site last updated: ".date("dS F Y h:i A", filemtime("/path/to/directory/."))." (PST).";

...but I'm not sure what to change the /path/to/directory/ to...

Is it the path as I see it in my FTP - that doesn't seem to work?
What does leaving a mere dot there mean?

filemtime(".") mean 'everything in the current directory'?


07-31-2007, 09:38 PM
If it's in the current directory, just use the filename eg: 'somefile.txt'

07-31-2007, 09:55 PM
Thanks, but perhaps I didn't explain clearly...

What I mean is that I want to check when ANY file on the whole site was last edited/updated/uploaded.

07-31-2007, 10:23 PM
Ah. Well filemtime() will check a single file. To use it the way you want, you'll have to loop through each of the files in the directory.

If you wanted to only check a subset of the files in the directory, you could populate an array with the filenames and loop through that.

08-01-2007, 03:01 AM
Erm, I'm confused... While I'm sure you're right, it seems that the following quote contradicts you. (This is taken from: http://de3.php.net/function.filemtime )

To get the last modification time of a directory, you can use this:

$getLastModDir = filemtime("/path/to/directory/.");

Take note on the last dot which is needed to see the directory as a file and to actually get a last modification date of it.

This comes in handy when you want just one 'last updated' message on the frontpage of your website and still taking all files of your website into account.

Am I missing something?
Thanks a lot. :-)

08-01-2007, 03:06 AM
To show the last modified date of the file that code is on you can use $_SERVER['SCRIPT_FILENAME'];
which will show use the script filename that the echo is running on.

While this information may or may not be what you need it might be useful to someone.

08-01-2007, 03:11 AM
Am I missing something?
Thanks a lot. :-)
Hmm. Wasn't aware that would work (obviously I've never tried it).

In that case, I'd try:


08-01-2007, 03:21 AM
Thanks _Aerospace_Eng_ ... useful for some other occasion! :-)

PappaJohn - I tried using /. but the date then shown is certainly much earlier than the last site update.

Of course, the guy who posted the quote I gave in last post may just be wrong(?)

OK, I'm trying to understand how to indicate paths: what does the full stop mean? And does a / with nothing before it indicate the root directory?

Regardless, to return to my problem, I'm simply looking for a way to print a "Site last updated on..." message in the footer of the site that will automatically detect the last time I uploaded any new/edited file.
Is the only way really to loop round an array of every file, checking each one's timestamp?


08-01-2007, 04:12 AM
This should work

echo "Site last updated: ".date("dS F Y h:i A", filemtime($_SERVER['DOCUMENT_ROOT']."/."))." (PST).";
What the $_SERVER['DOCUMENT_ROOT'] should return is something like this


08-02-2007, 12:27 AM
Almost there... Thanks a lot!

It successfully updates the date and time for any edited and re-uploaded files in the root directory.

The final step (I'm hoping this is just a small alteration neede?), is for it to recognise all subfolders too.

To what should I change:


My experiments are all failing! :-)

08-02-2007, 03:28 AM
What if you did just this?


08-02-2007, 12:21 PM
No, that's still only reflecting the last change to a file in the root directory, but not in all subfolders.

I ask again: I'm trying to understand how to indicate paths: what does the full stop mean? And does a / with nothing before it indicate the root directory?

I can't seem to find anything out about this, as I'm not sure what to Google for the info. "path syntax?" I'm guessing in the dark without that knowledge...