Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

CGI display a gif

by indie_campbell (Novice)
on Jun 06, 2005 at 15:47 UTC ( [id://463942]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I hope someone can help, i am getting little frustrated with regards to displaying a gif image. The image is in the same dir as the cgi script. It work using html code
<html><head><title>Results</title></head> <tr><td><IMG SRC="cgi-bin/images/1.gif"</td></tr> </table></html>
trying to adapt this to cgi code with no success, always get broken boxes
use CGI; print "Content-type: text/html\n\n"; print "<html><head><title>TESTING</title></head>"; print "<IMG SRC='cgi-bin/images/1.gif'>"; print "</html>";
I am viewing the cgi scripts using http://localhost/cgi-bin/image.cgi. I have checked the properties of the broken box and it points to the filel ocation and the image does exist. Thanks

Replies are listed 'Best First'.
Re: CGI display a gif
by ikegami (Patriarch) on Jun 06, 2005 at 15:52 UTC

    What's the URL of the image? Relative URL "cgi-bin/images/1.gif" applied to base URL "http://localhost/cgi-bin/image.cgi" is "http://localhost/cgi-bin/cgi-bin/images/1.gif". I think you have an extra "cgi-bin/" in there. Fix: print "<IMG SRC='images/1.gif'>";

    Also, how are you refering to the script? That script won't work from an <img> since it returns HTML, not an image.

      not sure if i understand ur second suggestion; wont form an <img> tag?
        The word "work" was missing. (I've just added it.) If you do <img src="http://localhost/cgi-bin/image.cgi">, you'll get a broken image since image.cgi returns HTML, yet your brower is expecting an image.
      the properties gives the location http://localhost/cgi-bin/1.gif
        Then it's just
        print "<IMG SRC='1.gif'>";
Re: CGI display a gif
by jhourcle (Prior) on Jun 06, 2005 at 16:10 UTC

    Right click (or equivalent) on the image with a broken box, and choose 'Open Image in New Window' (or equivalent).

    This will show you where the browser is trying to link to, and any error message that the server is ending to the browser.

    If that wasn't useful, check your web server's error logs. (I always keep a 'tail -f' running on my error logs when debugging -- anything that shows up in there is a problem, and needs to be dealt with ... even if it's script kiddies trying to root your site, search engines looking for 'robots.txt', or obnoxious browsers looking for 'favicon.ico')

      this directs me the right location http://localhost/cgi-bin/1.gif but reports an 500 internal server error??

        Which is what I suspected. (well, I actually expected a different URL, but I suspected the 500 error, or possibly a 403 (access forbidden, if it was trying to execute a file that didn't have execute permissions) )

        To confirm that bassplayer's and my suspicions are correct, you'll want to continue with the rest of my suggestion:

        If that wasn't useful, check your web server's error logs.

        You really should check your webserver's error log, as there's most likely something more informative in there. (well, maybe not, as it might throw some misleading errors if it's trying to execute something that's not an executable file.)

        Perhaps it's trying to execute the image instead of rendering it. The cgi-bin/ directory is special. :-)

        bassplayer

        Follow bassplayer's advice. Some servers treat everything in /cgi-bin (and subdirectories?) as scripts. Executing a .gif won't definitely result in a 500 error. You need to move your images outside of /cgi-bin.
Re: CGI display a gif
by bassplayer (Monsignor) on Jun 06, 2005 at 15:56 UTC
    I would recommend against keeping images in the cgi-bin, and place the images/ directory in the web root. You can ensure that this is accessed by changing the SRC attribute on your image tag to "/images/1.gif". The leading slash moves us out of the local directory.

    bassplayer

      i have noticed that the properties of cgi-bin foler are read only, does this make a difference (using XP)
        the question is why does it work with html code and not cgi though? seems odd
Re: CGI display a gif
by cool_jr256 (Acolyte) on Jun 06, 2005 at 15:53 UTC
    if your cgi script resides in 'cgi-bin' directory this should be sufficient:
    <img src='images/1.gif'>
      tried this also with no luck?
Re: CGI display a gif
by greywolf (Priest) on Jun 06, 2005 at 21:40 UTC
    If you want to see why the HTML page does not render correctly try looking at the page source from the browser. This will reveal where the script is trying to load the image from.


    mr greywolf

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://463942]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-16 23:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found