note 42040 added to function.filemtime
| From: | djhappylobster at hotmail dot com | Date: | Fri, 30 Apr 2004 13:08:51 +0000 |
| Subject: | note 42040 added to function.filemtime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69037@lists.php.net to get a copy of this message | ||
I use filemtime() to display a webcam image ONLY when it has been recently uploaded. This code is
useful for those who use webcams and do not want to change any php code when the cam comes online.
It prevents the old image from remaining on your site out of date, keeping your site
'fresh' and tidy. You could also use this code to display a 'my webcam is
online/offline' image.
<?php
$webcam_image="images/site/cam.jpg"; // Image to display
$offline_image="images/site/im_offline.jpg"; // Image to display when offline
(optional)
$keep_webcam_alive=1; // Maximum age of file (in hours)
// Display image if 'young' enough
if ( (time()-filemtime($webcam_image) )<60*60*$keep_webcam_alive){
echo "<img src='$webcam_image'>";
// Could also display another image
// informing users the cam is online
}
else {
if ($offline_image){
echo "<img src='$offline_image'>";
}
}
?>
Cheers
Mase
http://www.supercrab.com (php skills?)
----
Manual Page -- http://www.php.net/manual/en/function.filemtime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42040
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42040&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42040&report=yes
Search -- http://master.php.net/manage/user-notes.php