mike_preston Posted October 29, 2009 Posted October 29, 2009 Ok, so it's not directly related to the camera but here goes. My IP camera's up and running FTP'ing jpgs directly to the server, there is no onsite PC and I don't want to involve the use of one. The script on the webpage is replacing the image every 3 seconds however the snapshots come through at irregular intervals, no way to change that so no replies telling me to reconfigure the camera (trust me) i'm stuck with what i'm getting sent. My problem is I'm not to great at scripting and have used and amended a script from willing webcams. What's happening is the 3 second update frequently hit a half uploaded jpg and so 1 in 3 updates show a blank screen. What I need is a script that will check the file to update and if not available will display (not update) the previous jpg. Altering the frequency of update doesn't help 'cause of the irregular send from the camera. Any Ideas
IpCamSi Posted October 30, 2009 Posted October 30, 2009 Hi, Not sure about the scripting but some webcams have the option to upload tempory files which won't overwright the file until it is fully uploaded.
mike_preston Posted November 5, 2009 Author Posted November 5, 2009 Thanks for the reply but it doesn't really help. I'm happy enough with what the camera sends, it loads and replaces into a file on the server. The problem is the script i'm using then uses that file to update the image on the page. My script replaces the image every 3 seconds whether or not there's an complete image available. I need something that checks to see if the file is complete, if not don't replace and check again next time.
SteveBentley Posted November 5, 2009 Posted November 5, 2009 Assuming this is JavaScript/DHTML, I don't think you'll be able to query the file size or any other useful properly to find out whether it is fully uploaded. I think the best compromise might be to alter the script to show the image previous to the most recent one, which should have uploaded.
webman Posted November 5, 2009 Posted November 5, 2009 (edited) Do you have any server-side scripting capabilities on the web server, e.g. PHP? My thinking is this: Point the image to a PHP script (bear with me) The PHP script will check if the real image on disk is complete (using getimagesize() for example, it should fail if image is not valid) Set the content-type to image/jpeg If image valid from step (2) then respond with the image If not valid, then respond with another image that simply says 'Please wait...' Edited November 5, 2009 by webman 1
localzuk Posted November 5, 2009 Posted November 5, 2009 The way I'd do it would be a php script which checks the md5 hash of the uploaded file, compares it to the one which will be displayed, if it is not the same, then it overwrites the one to display with the uploaded one. If it is the same, it just displays. Example PHP code. $file1 = 'path/to/file'; //New file $file2 = 'path/to/file'; //Old file $md51 = md5_file($file1); $md52 = md5_file($file2); if(md51 == md52){ unlink($file2); link($file1,$file2); } Or something similar. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now