bighara has asked for the wisdom of the Perl Monks concerning the following question:

For some reason, the jpg I want to use for the background image doesn't want to load from my CGI script. I'm using essentially:

print "Content-type: text/html\n\n"; print <<Start; <HTML> <HEAD> <TITLE>PAGE TITLE</TITLE> </HEAD> <BODY BACKGROUND="image.jpg"> <H2>Header Line</H2></BODY></HTML> Start

The page generates, but the image doesn't load. I've also tried just sticking an image in the page (a la IMG SRC) and that doesn't work either. The JPEG is in the cgi-bin directory along with the script. I've tried it in a different directory as well, mapping to that folder in the 'BACKGROUND=' info, but no dice. Any thoughts? Or is it just some private weirdness of my system? Thanks.

Replies are listed 'Best First'.
Re: images & background images with CGI
by dws (Chancellor) on Jan 21, 2002 at 08:36 UTC
    The page generates, but the image doesn't load.

    Your web server's error logs might give you a hint.

    Try putting the image in the root of your web hierarchy, then write the BODY tag as   <body background="/image.jpg">

Re: images & background images with CGI
by foogod (Friar) on Jan 21, 2002 at 09:13 UTC

    dws gives a perfect example for how to fix this problem.

    For FYI sake, the reason this is happening is that you are calling your CGI from the /cgi-bin/ directory (or some other similar directory). And the web server is looking for your background image is this directory. By changing the SRC information for your image, you are telling the webserver the specific place to find your image.

    Another reason for the error is that you DO have the image in the /cgi-bin/ but that this directory only allows execution, and not viewing of files in these directories.

    HTH

    - f o o g o d

Re: images & background images with CGI
by grep (Monsignor) on Jan 21, 2002 at 09:24 UTC
    I have to post this, even though your HTML and your script are technically correct and it does not directly answer your question (dws's suggestion to check the log files would be my answer). I feel I should help you in the right direction of coding CGI with Perl correctly.

  • Use CGI.pm... use CGI;
  • check out Ovid's excellent CGI course
  • 2 books to own Lincoln Stein's Official Guide to Programming with CGI.pm and Writing CGI Application with PERL
  • If you are doing a site of any size use a templating system Template Toolkit, Mason, or HTML::Template. This will keep you HTML out of your code (they are not PB and Chocolate :).

    I wish there was a resource like Perlmonks around when I started and programming Perl and this is the info I wish someone would've given me if there were.

    HTH

    grep
    grep> cd pub
    grep> more beer
Re: images & background images with CGI
by little (Curate) on Jan 21, 2002 at 14:05 UTC
    Just to add one more way to do it:
    <BODY STYLE="background-image:url(/images/back.jpg); background-repeat:no-repeat; background-position:2cm 0cm;">
    which you can easily insert using the before and always mentioned CGI.pm.
    alike this:
    print start_html( -title=>'Body with background image', -style=>{'background-image:url(/images/back.jpg); background-repeat:no-repeat; background-position:2cm 0cm;'} );

    Have a nice day
    All decision is left to your taste