Display the date/timestamp of a file

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
paulpechey
Forum Newbie
Posts: 1
Joined: Sat Nov 13, 2004 3:23 pm

Display the date/timestamp of a file

Post by paulpechey »

I want to dynamically display the date that my web pages were updated, and figure I should be able to retrieve the date/timestamp of the file as a PHP variable, and then display it. However, I can't seem to find out how to do this anywhere. Can anyone help?
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

[php_man]stat[/php_man]()
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-

Hi,

If it should be the real date of a real file modified this is the way to get the filetime:

Code: Select all

<?php
// outputs e.g.  somefile.txt was last modified: December 29 2002 22:16:23.

$filename = 'somefile.txt';
if (file_exists($filename)) &#123;
   echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
&#125;
?>
*source: http://www.php.net/manual/en/function.filemtime.php

djot
-
Post Reply