Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error displaying .gif file within CGI 2

Status
Not open for further replies.

cosmoh2o

Programmer
Jul 22, 2002
92
US
Please help,

This problem has me stumped. I have created a perl script that will generate an html web page on the fly. The page is to have some images in it also so I have tried to embedded them. The following is a simplified version of the project but it encompasses the problem area of the program:
#!/usr/bin/perl -w
use CGI;
print "Content-type: html/text\n\n";

print &quot;<IMG SRC=top.gif>\n&quot;;
print &quot;<P>Hello World</P>\n&quot;;

The image &quot;top.gif&quot; is located in the directory which is running the perl cgi program and the permissions have been set to 755. The &quot;Hello World&quot; will print if I comment out the IMG line. However, the minute I put the IMG line back I get the dreaded &quot;Internal Server Error&quot;. Any help would be great, thanks.
 
Typically, your dynamic content (cgi code) and static content (html files and images and such) are held in different areas of your web server. With apache, typically they are 'cgi-bin' and 'htdocs'. The way you have your 'img' tag built, the browser will try to find the image in the root web directory on the web server, not the current cgi-bin dir.

In order for the image to work, it must reside on the server where it can be seen from the web. You should be able to point a browser directly at the image and display it in the browser, ......something like,
Once you can see the image in a browser, then use that url as the src for your image tag. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
I use a lot of cgi scripts to create dynamic html pages and I tend to use as the image root directory.

To make writitng scripts easier I create a variable at the start of the script:

$img_url='
(Note the missing trailing slash)

then when writing an image tag I use the variable like this:

<img src='$img_url/mypicture.gif' border='0'>

This way it is very easy to use the same scripts on different sites, or to re-locate the image folder later. This method is also very convenient if you are creating a script with different skins.

Have fun
Taffelman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top