Friends: Here's a nice mystery for you. I've been losing sleep over it for about six weeks. No one on the Community Board at my host has been able to suggest a solution.

The cgi in question is the following script, Example 3-4 from the the Mouse book, as corrected from the Oreilly web site:

#!/usr/bin/perl -wT

use strict;

my $image_type = $ENV{HTTP_ACCEPT} =~ m|image/png| ? "png" : "jpeg";
my( $basename ) = $ENV{PATH_INFO} =~ /(\w+)/;
my $image_path = "$ENV{DOCUMENT_ROOT}/images/$basename.$image_type";

unless ( $basename and -B $image_path and open IMAGE, $image_path ) {
    print "Location: /errors/not_found.html\n\n";
    exit;
}

my $buffer;
print "Content-type: image/$image_type\n\n";
binmode STDOUT;

while ( read( IMAGE, $buffer, 16_384 ) ) {
    print $buffer;
}

I call the CGI from my browser with
reason.net/cgi-bin/image_fetch.cgi/tour.jpg

My problem is that I get 404 errors. There are 3 tests on the "unless" line. By trying with various parts deleted, it seems that I am passing the first, but not the second (Binary) and third (Open). When I delete the second and third test, my browser receives a blank (no source code at all). The first thing I looked for was images in the wrong place, but they seem right.

Inserting print statements to print out the variables for examination, I found that $image_path was
/big/dom/xreason/www/images/tour.jpeg (document_root on my server is /big/dom/xreason/www )
I think this is the correct path.
I have both tour.jpeg and tour.png assigned permissions of 644 and stored in the file
www.reason.net/images/
so the 404 should not have been caused by a missing type of file.


It seems to me that the server is looking in the right place for the file; is it possible that I am wrong about this?

Assuming it is looking in the right place, why does my image flunk the binary and open file tests? What can cause this? Alas, the mystery haunts me.

All bright ideas and educated guesses will be accepted with gratitude. Thanks! Rick Triplett

Reply via email to