note 42040 deleted from function.filemtime by tomsommer
| From: | tomsommer@php.net | Date: | Fri, 30 Apr 2004 20:04:27 +0000 |
| Subject: | note 42040 deleted from function.filemtime by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69047@lists.php.net to get a copy of this message | ||
Note Submitter: djhappylobster@hotmail.com
----
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?)