<?php
//*******************************************************************************
// Retrieve an image and display it on the web
// Make sure that there is no HTML or PHP output other than the readfile( )
// This script also adds a cookie (image name) as part of the response 
//*******************************************************************************

$filename  = $_GET['file'];

if (file_exists($filename))                                     #if file exists
{ 
    header("Content-type: image/jpeg" );            
    header("Set-cookie: image=" . $filename . "; path=/" );         
    readfile($filename);                                        #read a file and write it to output         
}
elseif($filename)                                               #file does not exist
{
    die("<h2>File $filename does not exist</h2>");
}
else                                                            #nothing was entered in query_string
{
    print("<h2>Please enter imgServer?file=...</h2>");
    include "../include.php";    
    exit;
}
?>