note 5068 deleted from function.fileatime by vincent
| From: | vincent@php.net | Date: | Sat, 16 Aug 2003 21:06:39 +0000 |
| Subject: | note 5068 deleted from function.fileatime by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-54469@lists.php.net to get a copy of this message | ||
Note Submitter: cjlambert@gamespy.com
----
Here's a little snipping to show "Last accessed ______ ago." This can also be applied
to last modified.
<pre>
$lastvisit = fileatime("______FILE-NAME-HERE______");
$currenttime = getdate(time());
$currentdate = $currenttime["0"];
$difference = $currentdate - $lastvisit;
$hours = $difference / 3600;
$minutes = $difference / 60;
$seconds = $difference - ( intval($minutes) * 60 );
$intmin = intval($minutes);
$inthour = intval($hours);
if ($inthour == "1") { $hour = "hour"; } else { $hour = "hours"; }
if ($intmin == "1") { $minute = "minute"; } else { $minute =
"minutes"; }
if ($seconds == "1") { $second = "second"; } else { $second =
"seconds"; }
if ($difference < 60) { print ("Last accessed: $seconds $second ago.<br>\n"); }
elseif ($difference < 3600) { print ("Last accessed: $intmin $minute and $seconds $second
ago.<br>\n"); }
elseif ($difference < 86400) { print ("Last accessed: $inthour $hour, $minutes $minute and
$seconds $second ago.<br>\n"); }
</pre>
Keep in mind that if it hasn't been accessed for over a day, it won't print anything. This
is due to my laziness since all files using this should max out at < an hour :)
Enjoy!