I'm writing a modperl application (running under
Apache::Registry) where i decided to serve images from the DB for various reasons.
I got a simple CGI script to serve images, it looks like this:
use strict;
use lib '/path/to/my/lib/';
use MyDBI; #export $dbh
use CGI qw(header path_info);
my ($id, $image) =
path_info() =~ m{(\d+)_((?:image|thumb|mini)[1-3])(_.+)?\.jpe?g$}
+i;
exit unless $id and $image;
my ($file) = $dbh->selectrow_array("SELECT $image from offerte WHERE
+id=$id");
exit unless $file;
print header(-type => 'image/jpeg', -Content_length => length $file),
+$file;
This is working fine except for caching. Browsers keeps on asking conditional GETs sending If-Modified-Since fields.
As the filenames changes if the image changes all i want to do is just replying a 304 header if i receive a conditional GET.
Can i do it with a simple script like mine, do i have to use Apache API or do i have to install an Apache handler?
$|=$_="1g2i1u1l2i4e2n0k",map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.