/    Sign up×
Community /Pin to ProfileBookmark

Display the last uploaded image on a page

We have a camera which uploads images to our webserver every 15 seconds. This static image is displayed on a page, and refreshed to show the latest image. This is uploaded as “webcam.jpg”.

I’d like to change the upload such that it uploads a set number of images. This will up upload images as “webcam1_1.jpg” through to “webcam1_480.jpg”.
Once 480 is uploaded, it resets to 1.
Ultimately I aim to wrap all 480 images into an 60 second loop of the previous 2 hours captured.

Is it possible to determine the newest image uploaded to the webserver and display this image each 15 second refresh?
For example if the latest image is webcam1_178, this image is displayed on the page. When next checked, it finds webcam1_179 and displays this image.
Date modified on the image includes the date and time uploaded.

I don’t use PHP, but that’s the language our webserver needs so I appreciate any help!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayJun 27.2013 — Easiest way would be to read the directory information into an array and sort on the modification date/time.

Something close to:
[code=php]
$files = array();
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$files[filemtime($file)] = $file;
}
}
closedir($handle);


// sort
ksort($files);
// find the last modification
$reallyLastModified = end($files);

foreach($files as $file) {
$lastModified = date('F d Y, H:i:s',filemtime($file));
if(strlen($file)-strpos($file,".swf")== 4){
if ($file == $reallyLastModified) {
// do stuff for the real last modified file
}
echo "$file$lastModified";
}
}[/code]
Copy linkTweet thisAlerts:
@Mac_NzauthorJun 27.2013 — Thanks for the quick reply!

How do I add the directory the images are in for the array?

The images are all .jpg, should the ($file,".swf") in the foreach be .jpg?
×

Success!

Help @Mac_Nz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...