Page 1 of 1
Displaying webcam images - got a recursive dir Iterator
Posted: Fri 27 Feb 2015 12:16 pm
by Warrandyte
http://www.warrandytefarm.com/test/getimagenames.php
the code is below for anyone who wants one that works on php4+
Code: Select all
<?php
/**
* @author Rob France
*/
$myfile = new RecursiveDirectoryIterator("webcam/");
$display = Array ('jpeg', 'jpg' );
foreach(new RecursiveIteratorIterator($myfile) as $file)
{
if (in_array(strtolower(array_pop(explode('.', $file))), $display))
/** echo "<img src='" . $file . "'width='600' height='400'><br/> \n";
uncomment the above to display the images */
echo $file . "<br/> \n";
}
?>
now I have that's going, I need to filer by camera number and date, probably using drop downs but I get kind of stuck there.
its been a lot of headaches trying to get all the recursive stuff to work
webcams is a subdirectory of the root from where the script is run
another one getimages.php will give the images using the same code but theres a lot of them and i dont want to blow peoples bandwidth
There is probably also a much better way of doing this using glob functions or similar but I cant convince my hosting people to get away from php4
I have used the filenames Cam1_ cam2_ etc and the dates are the main folder names apart from a few rogues that have crept in there.
Re: Displaying webcam images - got a recursive dir Iterator
Posted: Fri 27 Feb 2015 1:03 pm
by beteljuice
Warrandyte wrote:the code is below for anyone who wants one that works on php4+ ...
I've never seen / used
Code: Select all
RecursiveDirectoryIterator()
RecursiveIteratorIterator()
according to the blurb they are php
5.
I'd be doing it a more 'old fashioned' way.
now I have that's going, I need to filer by camera number and date, probably using drop downs but I get kind of stuck there.
Really need an example of a couple of 'full' file path / names, plus how do you want to present them ?
eg. latest / asked for one then list of others, or perhaps latest / asked for one then thumbnails of the others ? etc. etc.
Re: Displaying webcam images - got a recursive dir Iterator
Posted: Fri 27 Feb 2015 11:05 pm
by Warrandyte
They all list under the link.
Apologies i meant 5.4 rather than 5.5. My subversive subversion thinking.
I went to throw them all into an array sorted by filename which gives the date and filtered by camera number which is the Filename prefix (as i think most cameras allow this method)
As you can see from the output they list under webcam folber by date yyyymmdd then subfolders by hour (h24)
However to give a general solution others can pick up and use then it probably needs to be a bit configurable.
Images vary but getting the latest image for a certain file prefix eg Cam1 would be preferable.
Then being able to select backwards by date or time or hour in this case.
I was surprised there wanst already a gallery page out there already but i gather its beyond many people.
Of all the coding sites no one ever posts a final solution leaving everyone to reinvent the wheel.
For those of us that develop in the 5 spare minutes a day between screams of kids. Its hard to keep focussed.
Oh the good old days doing GPS stuff where i could just stay up all day and night, even take the laptop to the park or coffee house!
Re: Displaying webcam images - got a recursive dir Iterator
Posted: Sat 28 Feb 2015 12:55 am
by beteljuice
I'm still not following your directory architecture ....
are you saying:
webcam/yyyymmdd/[h01 > h24]/...
cam1_?????.jpg
cam2_?????.jpg
... and what is the format of _?????, eg. would there be more than one instance of cam1_ in eg. h01 folder ?
It doesn't look like the friendliest of structures to reverse engineer, especially as the cam id is last man in.
... and although I've never used it I'm a little concerned about:
Code: Select all
foreach(new RecursiveIteratorIterator($myfile) as $file)
{
Shouldn't that be more like ?
Code: Select all
$iterator = new RecursiveIteratorIterator($myfile);
foreach($iterator as $file)
{
Re: Displaying webcam images - got a recursive dir Iterator
Posted: Sat 28 Feb 2015 5:02 am
by Warrandyte
/webcam/yyyymmdd/hh/Cam(x)__YYYYMMDDhhmmssms.jpg and its a bugger.
the number of images is dependant on the hour divided by minutes per image (or seconds per image if you had unlimited bandwidth)
4 cameras, same (ha ha) firmware versions
2 different methods
two under YYYYMMDD directly, the other two use the subfolder by hour and you cant do much about the image name.
Ive tried a few different cams to see if there was one good version, but no, and writing something like this it may as well take care of a few types of cameras.
I have tried so many camera and application combinations but they all seem to have issues. yawcam was great till I moved OS then it wouldn't work again, and 4 instances were very resource hungry, same with webcamxp and webcam7.