I had a previous thread that Dan and Walt helped me out on. I was trying to figure out how to create a page that would stream webcam video to a page, that didn’t seem to work. I’ve contacted the webcam manufactures to see if they can help, but in the meantime, I have come up with another solution.
Rather than having the camera stream live video, I’ve set the camera to take a snap shot every few seconds and then ftp that image to a folder on the server.
Is there some bit of coding magic I could insert into a freeway generated page that would grab and display the most recent file placed into a folder?
That’s pretty simple to do in PHP. Getting the latest file could be done in a couple of ways. Does your camera name the files in a sequential order? If so, then you would do something like this:
$pictures = scandir('/path/to/the/photos');
//if the latest is last alphabetically
$picture = array_pop($pictures);
//or, if the latest is first alphabetically
$picture = array_shift($pictures);
print '<img src="photos/' . $picture . '" alt="" />';
/path/to/the/photos is a server root relative path to the photos. So if you are using FTP to get to your server, and if your Web root is /home/yourname/htdocs/ and you put the photos in /home/yourname/htdocs/photos, that would be what you enter there.
You only need to use either array_pop OR array_shift, depending on the alphabetical order of the images as saved by this camera. Delete or comment out the other one.
The last line is just a starting point for you, you would want to add the image height and width to the tag as well. If you named the folder something other than photos, you would change that here to match. This is written as though your photos folder is in the same directory on the server as the page that contains this code, so if you were looking in the folder, you might see:
Paste this code into a Markup Item on the page where you want the photo to appear. Make sure that the Markup Item is large enough to show the whole photo, and you should be good.
Well it might be, but I just ran into another snag.
Found out that the camera rather than just ftp-ing the image to the specified folder will create two additional folders automatically inside the specified folder. I’m guessing it does this to “help” organize the files. So instead of the path to the the lastest picture looking like this /photos/latestpic.jpg, it happens like this, /photos/20100617/06/latestpic.jpg
I understand that the 20100617 folder is todays date…not sure why then it creates the next sub folder inside of that folder, perhaps a new folder is created every hour. I’m assuming that this would make the php code you gave me not work since the file paths wouldn’t match up. Also the pictures are numerically name based on a date and time format.
I’m thinking about asking the client if we can check out the possibility of a web cam that is meant to be a web cam. This camera is a high dollar security camera…using it as web cam is a secondary unsupported feature (according to the camera’s manufacturer’s website)
That’s relying on my hunch that the folder is named YearMonthDay/HoursIn24HourFormat, and that the last image in alphabetical order is the one you want. Change to array_shift if you want the first in alphabetical order.
I finally had some time to go back over this again and I think I’ve made a real mess of it.
I’m not sure if I understand how to add the file path correctly, here is the ftp path to the photos…frontrangeweb.startlogic.com/public_html/webcam
I’m not sure which functions in the code to use based on how the camera names the photos. The camera adds the following file name protocols to the webcam folder, and picture file names,
Once you have that, put it into the first set of quotes inside the line that begins with $folder =. That path has to begin with a forward slash, meaning you’re starting from the very root of the server’s file tree. The next line creates the next two segments of the path (date/hour) and finally the line that begins $image = simply grabs the alphabetically-last image inside that folder.
To add the dimensions to the image tag, you simply add width="640" height="480" into the tag, either before or after the alt= part, and separated from all other attributes by a space on either side.
I’m still flummoxed by figuring out the correct file path.
If I emailed you off list and gave you access to the server do you think you could enlighten me?
I’m going to to still keep at it, maybe my hosts control panel might help shed some light on this too.
The trick is to use an FTP app like Transmit, log in to your hosting space, and then pull down the little picker (Transmit 3) or click on the left-most segment of the breadcrumbs (Transmit 4) at the top of the right pane. That will show you the “root” of your path. Some servers are set up so you don’t get to see the very root of the server, they use what’s called a ‘chroot jail’ to give you your own root where you can’t screw anything up. That depends a lot on the server. Once you see just how far up you can go, you can figure out what the root-relative path is to your folder, and then the rest will just work.