[Pro] Web Cam work around question...

Hello,
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?

Thanks,
Rich


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

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:

<?php
$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:

/photos
webcam.php

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.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On 17 Jun 2010, 11:42 am, waltd wrote:

That’s pretty simple to do in PHP.

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)


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You could modify the function to always get the latest image for today:

$time = date('Ymd/H');
$folder = '/path/to/folder/' . $time;
$image = array_pop(scandir($folder));
print '<img src="folder/' . $time . '/' . $image . '" alt="" />';

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.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks again Walt…
I feel like there might be a light at the end of the tunnel here…will probably be back again with questions when the cave in happens.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I finally had some time to go back over this again and I think I’ve made a real mess of it.

  1. 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

  2. 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,
    /yearmonthday/24hour/photo_yearmonthday_hourminsec_D.jpg

so a complete path to a file for a picture looks like this,
frontrangeweb.startlogic.com/public_html/webcam/20100619/08/photo_20100619_083254_D.jpg

  1. Not sure how to add the image size tag into the code, the picture is 640px by 480px.

  2. Finally does the page that this code is to be added on to need to be a .php page?
    So here is the code I’m adding…sans image size tag.

<?php $pictures = scandir('frontrangeweb.startlogic.com/public_html/webcam'); $time = date('Ymd/H'); $folder = '/frontrangeweb.startlogic.com.public_html/webcam' . $time; $image = array_pop(scandir($folder)); print '';'; ?>

Here is the page I’ve made the mess of,
http://frontrangeweb.com/webcam/webcam.php

Thanks for any help. I should either be hiking or fly fishing right now…stupid webcam!


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

First off, the $pictures = line is left over from the first attempt. You can delete that line.

Next, if you use an FTP client to log into this folder, what do you see? Can you navigate to a point where you see a path that begins with / ?

What you need to determine is the absolute-root-relative path to your folder of images, something like this:

/home/username/frontrangeweb.startlogic.com.public_html/webcam/

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.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walt,
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.
Thanks again.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

That’s fine, check my profile for the address.

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.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options