How to Embed The Most Recent Uploaded Image – Linksys WVC54GCA

OK, so another common want people have asked me about with regards to embedding their cam on a web page, is how to embed a camera image. I did this with my Linksys WVC54GCA, but this script will actually work with any files. Since this cam has no regular upload interval, I am relying on the motion detection (which is really sensitive) to trigger the upload.

Since I have already outlined how to setup the FTP upload, I am not going to cover that in this post. When you setup your FTP upload, be sure to specify a separate directory to hold your images, as this script is going to look for the most recent file and delete the rest. This is one that some people get hung up on in the FTP setup. Be sure to create your directory (for example the directory might be called images), using an FTP program and then specify the directory path in the cam setup like this: /images.

Links to the image embed script and instructions on how to use it are listed below.
file with last mod time.

Ok, in order for this script to work, your hosting server must be capable of running PHP scripts. You must also know the absolute directory path to your hosting directory. Start by downloading this text file (right click and save as may work the best). Once saved, open it in your favorite text editor. You will need to set the $dirpath variable with your directory path. Save this file as latest.php As suggested above your camera should be uploading it’s images to a directory within your hosting root. Upload latest.php to the same directory your camera is uploading images to. If you change the name of the script or have any other files in this directory that you do not want deleted you must add them to the script below the comment set beginning with ### EXCLUDE HERE. This script will delete all files except for those that have been excluded and the most recent file based on last modified time.

Once the script is in place with your camera images, you can test it by accessing it directly. Mine is located here. Next, you can include this file in a separate php file using include 'images/latest.php'; This will allow you to embed the most recent camera image on any page that you are able to include a php file in. In most cases you you change the name from index.html to index.php and add the line above with and opening and closing php tag.

Ok so I hope this helps, please post comments if you get stuck anywhere in the process. I will try to help when time permits. Incidentally, this script should work for any cam configured to upload images, or in any situation where you need to display the most recent file based on last modified time. For those of you that are new, and looking to embed the camera stream, check out How to Embed a Linksys WVC54GCA Video Stream in an HTML Web Page.


  1. Jeeves Don't Ask:

    Cool, this is what I want to do! The stream sucks all of my bandwidth, so I want to post and image on my page like you have. I know nothing about php. Opening and closing tags, include, all of this is vague. The article does not do much good if you don’t explain the rest of it, at least for me.

    Your embed post is good, but this one seems like it’s lacking details.

    I you could elaborate on what to do with php to get this to work it would be grand!


  2. Mark:

    Yeah Jeeves, wordpress was stripping out any code I was trying to add. I see how to add the code now. So, if you have an html file called home.html one level above your images directory, change the name to home.php Next, add this line where you want your image to appear on the page.

    <?php include 'images/latest.php'; ?>

    Don’t forget you would need to change any links that were pointing to home.html to home.php. You can add bits of PHP to all of your HTML pages to make them a bit more dynamic. For this reason, I would always name your files with the .php extension.

    In order to add use includes in WordPress, I installed one of the many PHP code plugins that are available on the net. PHP-Exec

    I hope this helps,

  3. Sam G.:

    Will this script work to embed an image in Drupal also? I have been working at it and I don’t think it is allowing me to use the include statement as you have it posted. Is there something else I could try?

    Great site BTW!


  4. Lisa:

    It seems like it would be easier to simply use the built in URL that snaps an image when accessed. There would be no need for any of this. I just don’t know how to embed it into a page. Does anyone know what I mean here? It is in the manual.


  5. Adam:

    I’m trying to find a way to upload the streaming video to my hosted site and let users view it from there. I have darwin streaming media server loaded but really don’t know how to set up the relay. Any help? Thanks. If this works it will be one more aquarium on the internet! Two actually when I get the big one up and running next week.

  6. Anel:

    Adam, did you ever got the WVC54GCA working with darwing streaming server?

  7. Mark:

    This page provides instructions allowing the the most recent image to be embedded on a web page. This makes use of the FTP feature but it also does the housekeeping of only keeping the most recent image on the server whenever the pages is accessed. A CRON job could be setup as well, in case the page is not viewed on a regular basis. I have not played with Darwin Streaming server for quite sometime, but I think you could do it. If you have the videos uploaded instead of the image as I have here. I could come up with a way to display uploaded videos in a menu format based on date and time if this is what you’re looking for.


  8. Ben:

    I’m trying to use the “latest.php” script for this. It seems to run the loop, but no files get deleted or renamed. Are there differences in the way PHP is implemented across platforms?

  9. Mark:

    Hi Ben, double check the path variable I guess as well as permissions on the files. Are you running this on windows?

  10. Ben:

    I’m running it on a Linux host. The files and directory are all rw for the owner. I just tried changing the write permissions, and it appears to want to work. So that must be the issue. Thanks for the suggestion.

  11. Mark:

    Great! Yeah, Apache (or whoever your web server is running as) would need the ability to write to the files in that directory. It’s not really a security issue if you only change the perms on those files. As a matter of fact you could simply add the chmod command just before the rename. This way the the files are read only until the script runs. Let me know if you still need a hand, but it sounds like you’ve got it.

    Happy Holidays!

  12. Ben:

    I finally got the kinks worked out. Now I just need to figure out why my WVC210 won’t do anything for motion detection. I have another camera that is working fine with this setup. Thanks a bunch. I’ve worked with a lot of languages and program environments. This is my first venture into PHP.

Leave a comment