httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Meadors <>
Subject Re: [users@httpd] Handler for images in a directory.
Date Tue, 04 Mar 2003 19:54:53 GMT
Kevin Robert Casey wrote:
> what about the idea of using mod_rewrite?  i'm not up on the syntax, but
> have apache rewrite requests for "/protected-dir/([\w|\d]+)\.jpg" to
> "/cgi-bin/protector.cgi?file=$1.jpg"?
> it will keep the developer (if it isn't yourself) happy because they just
> link to the images as they usually do, but you can implement any
> restrictions you want inside protector.cgi.

You are right, I'm not the site developer, so that was one thing I 
wanted to keep the same, that the links to existing images still worked.

Here's what I ended up with today.

An .htaccess file in the protected directory that says:

Action image/jpeg /cgi-bin/image_handler.cgi

So any JPEGs in that directory will trigger the image_handler.cgi 
script.  That script is pretty simple:

#! /usr/bin/perl
if ($ENV{REQUEST_URI} =~ /cgi-bin/) { die; }
         print "Content-type: image/jpeg\n";
         print "Pragma: nocache\n";
         print "Cache-Control: no-cache, must-revalidate, no-store\n\n";
         open("IMAGE", $ENV{PATH_TRANSLATED});
         while (<IMAGE>) {
                 print $_;
} else {
         print "Content-type: text/html\n";
         print "Pragma: nocache\n";
         print "Cache-Control: no-cache, must-revalidate, no-store\n\n";
         print "<html><head><title></title></head><body 
oncontextmenu=\"javascript:return false;\" 
onselectstart=\"javascript:return false;\" ondrag=\"javascript:return 
false;\"><img src=\"$ENV{REQUEST_URI}\"></body></html>";

That last print should all be one line.


The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message