Click to See Complete Forum and Search --> : CGI script to producing HTML image page


jimbob2812
03-26-2003, 09:16 AM
I have created a perl script called "photo.pl" -

#! /usr/bin/perl
$photo=$ENV{QUERY_STRING};
print "Content-Type: text/html\n\n";
print "<html><head><title>James Davies - Photo</title></head><body>"
print "<img src=\"pics/$photo.jpg\" />\n";
print "</body></html>\n";

This is correctly interpreted by my server to give the following HTML code (when invoked with "?img01big" as the query string at the end of the URL...) -

<html><head><title>James Davies - Photo</title></head><body>
<img src="pics/img01big.jpg" />
</body></html>

But the image is not displayed. When I copy the generated HTML code from the web to my local PC into the directory where the original "photo.pl" source is, it works as expected and the photo is displayed.

I have checked the authorities and that the directory "pics" exists with the image inside. All ok...

The web log on my server has this which I guess is the problem - somehow it has decided to insert the "/html" into the path name -
14:44:36 2003] sbox: exec of /users/netm/domains/netmotorway.co.uk/html/cgi-bin/james/gite/pics/img01big.jpg failed

But the bizare thing is that the directory "cgi-bin" is held within the top level directory of netmotorway.co.uk...

Can anyone help me find out what is going on please, as this is driving me mad...Cheers, James

Scriptage
03-26-2003, 02:58 PM
Try changing this line:
print "<img src=\"pics/$photo.jpg\" />\n";
To this:
print "<img src=\"full_site_path/pics/$photo.jpg\" />\n";

This should work.

If not send me an e-mail with the subject webdeveloper forum
to batesy1986@hotmail.com, and I'll re-write your entire program.

Regards

Scriptage
03-26-2003, 03:00 PM
where full_site_path is the full path to your site eg http://www.blahblah.co.uk

jimbob2812
03-27-2003, 03:03 AM
Cheers for the reply Scriptage. Tried your suggestion and still no joy.

However, the photos were stored in a directory called "pics" within the "cgi-bin" directory.

This is why the original script was simply -
print "<img src=\"pics/$photo.jpg\" />\n";

(ie. the perl script has to be within the "cgi-bin" directory on my server,
so I just created a sub-directory "pics" one layer below to hold the images)

Even with full path of :
print "<img src=\"http://www.netmotorway.co.uk/cgi-bin/james/pics/$photo.jpg\" />\n";
it still did not find the images...

However, when I moved the directory "pics" out of the "cgi-bin"
and put it anywhere else on the server, everything works.

This is true for relative paths of -
print "<img src=\"../../../temp/james/pics/$photo.jpg\" />\n";
or absolute/full paths as you suggested...

So, this leads on to asking a stupid question:

Must the "cgi-bin" directory ONLY contain cgi objects ?
(ie. no images, .html pages etc etc etc)

Scriptage
03-27-2003, 05:59 AM
As far as I'm aware there shouldn't have been any problem with having the images in the cgi bin.
The problem may have come from file permissions.
If you type the path to your cgi-bin in to the address bar it is more than likely that it will say permission denied. This will apply to the image directory aswell. Try changing the file permssions of the image directory to 0755. This should allow everyone to see the images.

Regards
Carl