It seems cgi-bin blocks images.
Putting a document in the cgi-bin tree is an instruction to your webserver that it is supposed to execute the file, not just serve it up. This leaves two general choices: put your images in another branch of the www tree (e.g. html) or put your images in cgi-bin/images or equivalent, and use a script like the following to serve them up:
#!/usr/bin/perl -wT
use strict;
use CGI;
my $cgi = CGI->new;
my ($id) = $cgi->param('id') =~ /^(\w+)$/;
my $filename = "$id.png";
my $content = eval {
open my $fh, '<', "images/$filename" or die "Open failure: $!";
binmode $fh;
<$fh>;
}
print $cgi->header(-type => 'image/png',
-expires => '+1h',
-content_disposition=>"inline; filename=$filename"
);
if ($content) {
print $content
} else {
open my $fh, 'images/none.png' or die;
binmode $fh;
print <$fh>;
}
Note that I've assumed all images are in one directory, and that id's are all word characters (alphanumerics or underscore). It is very easy to make a script that looks a lot like this to will serve up any file on your file system, so pay attention to what paths you let through.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|