Forum Moderators: coopster
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("d/m/Y",filemtime($pfile));
?> Now I'd like it to be able to do the following:
I'm sure the answer is buried somewhere on php.net but I could not find it. I imagine this might take more code than I expect. Also I'm using XAMPP on Windows XP right now if that matters.
Thanks for any pointers or code samples!
[edited by: MrWumpus at 10:04 pm (utc) on Jan. 29, 2008]
Look at strtotime() [php.net]. This is a very handy function that goes the other way - it converts "plain text" into timestamps. For example:
strtotime("-30 days");
will give you the timestamp for thirty days ago. So you could easily compare the timestamp you get from filemtime() to the timestamp produced by strtotime to figure out if the file has been modified in the last 30 days.
$lastmonth = strtotime("-30 days");
$mtime = filemtime($pfile);
if($mtime < $lastmonth)
echo "This file hasn't been modified in over 30 days";
else
echo "This file has been changed within the last 30 days";
Your example works just fine with filemtime() and I see on php.net that there is also filectime() function that returns creation date, although filectime does not work properly on Win32.
Now off to the paint program to make those new and updated GIFs!