Hers my code -
#!/usr/bin/perl
$lifetime = 2*60 ; # image expiry time
# load the HTTP date routines
$libloc = "/usr/local/lib/libwww-perl-0.40" ; unshift(@INC, $libloc);
require "timelocal.pl" ;
require "wwwdates.pl" ;
$path = $ENV{'PATH_INFO'} ; $query = $ENV{'QUERY_STRING'};
$pragma = $ENV{'HTTP_PRAGMA'} ; $pragma =~ tr/A-Z/a-z/ ;
$imsd = $ENV{'HTTP_IF_MODIFIED_SINCE'} ;
$ims = $imsd ; $ims =~ s/;.*// ; # for Netscape
$ims = &wwwdates'get_gmtime($ims) ;
$file = "./shut.jpg" ;
# find the modification time of the cached image and work out
# its age
#if ($ims && $modtime<=$ims) {
# print "Content-type: text/plain\n\nError opening file\n";
# print "Status: 304 Not Modified\n\n" ;
# exit ;
#}
# set expiry time. Agents will automatically load a new image
# if their cached version is older than this.
$expires = time + $lifetime ;
# Convert expiry and last-modified times to RFC1123 time
$gexpires = &wwwdates'wtime($expires,'GMT');
$glastmod = &wwwdates'wtime($modtime ,'GMT');
open (JPG,$file) ;
$jlen = read (JPG,$doc,50000) ;
if (!$jlen) {
print "Content-type: text/plain\n\nError opening file\n";
exit ;
}
# Generate the complete HTTP response for a successful GET
print "Content-type: image/jpeg\n";
print "Last-Modified: $glastmod\n";
print "Expires: $gexpires\n";
print "Content-Length: $jlen\n";
print"\n";
print "$doc";
The first time I run this from my browser, the image displays fine, but if I hit reload (on IE6 or NS) I get Internal Server Error. If I hit back then forward, the image reappers - its loaded from the cache as there is no download pause.
I wish to start playing around with "Status: 304 Not Modified"(commented out at the moment) as I'm trying to cache SVGs and ive been informed that I'll need this to get IE to work - the guy who's giving me advice doesnt script in perl so I'm leaving my code as simple as possible - hence no CGI.
Any ideas as to what I'm doing wrong?
thanks,
Barry.