<?

// webcam_filename is single image file uploaded
// by webcam ftp upload utility
// im using "WheresJames Webcam Publisher"
$webcam_filename = "webcam.jpg";



// DO NOT EDIT BELOW THIS LINE
// UNLESS YOU'RE GOOD @ PHP
// -----------------------------------------------------------

ob_start();

$webcam_dir = str_replace('.','',$_GET['dir']);

$webcam_image = "";

function
grabWebcam()
{
    global
$webcam_image, $webcam_dir, $webcam_filename;
    
$webcam_filename = "./$webcam_dir/images/$webcam_filename";
    
$fd = @fopen($webcam_filename, "r");
    
$fc = @fread($fd, filesize($webcam_filename));
    @
fclose($fd);
    
$webcam_image = $fc;
    if (
$fc)
    return
true;
    else
    return
false;
    
}

function
getImage()
{
    global
$webcam_image;
    if (
grabWebcam())
    {
    
header("Content-type: image/jpeg");
    echo
$webcam_image;
    }
}

function
showWebcam()
{
    global
$webcam_dir;
    echo
"
    <html>
    <head>
    <meta http-equiv='pragma' content='no-cache' />
    <meta http-equiv='cache-control' content='no-cache' />
    <meta http-equiv='expires' content='Fri, 11 May 1990 22:10:06 GMT' />
    <meta http-equiv='date' content='Fri, 11 May 1990 22:10:06 GMT' />
    </head>
    <body onLoad=\"updateImage()\" topmargin=0 leftmargin=0>
    <img id=webcamimg name=webcamimg />
    <script language='javascript'>
    var timerId = 0;
        function updateImage()
        {
            var elem = document.getElementById('webcamimg');
            elem.src='image.php?dir="
.$webcam_dir."&t='+(39784*Math.random());
            timerId = setTimeout(updateImage, 2500);
        }
    </script>
    </body>
    </html>
    "
;
}

?>