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.

In reply to Trouble Caching an Image by Baz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.