giulienk has asked for the wisdom of the Perl Monks concerning the following question:
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:
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?
This is working fine except for caching. Browsers keeps on asking conditional GETs sending If-Modified-Since fields.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;
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Caching images from RDBMS
by tadman (Prior) on Aug 08, 2002 at 10:41 UTC | |
by giulienk (Curate) on Aug 08, 2002 at 10:54 UTC | |
Re: Caching images from RDBMS
by perrin (Chancellor) on Aug 08, 2002 at 12:03 UTC | |
by giulienk (Curate) on Aug 08, 2002 at 12:25 UTC | |
by waswas-fng (Curate) on Aug 08, 2002 at 14:47 UTC | |
by giulienk (Curate) on Aug 08, 2002 at 16:26 UTC |
Back to
Seekers of Perl Wisdom