Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

<img> tag does not work in my perl/cgi code

by vit (Friar)
on Feb 23, 2008 at 20:40 UTC ( [id://669765]=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks,
I need your help. My Perl CGI script generates HTM file with
<img src="images/image.jpg" alt="site_image" width="800" height="200">
My perl file is in cgi-bin directory and everything works fine except oppening img.
When I create HTML file from the view/source in my IE6 it works fine (image is shown).
Any idea what may be wrong?

Replies are listed 'Best First'.
Re: <img> tag does not work in my perl/cgi code
by ikegami (Patriarch) on Feb 23, 2008 at 21:11 UTC
    Is the image really located at .../cgi-bin/images/image.jpg?

    should probably one of:

      Yes, exactly there. Besides, when I get source from my web page where image is not shown, save as HTML file, place it in /cgi-bin/ directory it opens with image. Why?

        vit, webservers are not usually configured to render images in a CGI/executable mapped directory. The only thing that happens to files residing in these trees is that they are executed (ie. scripts etc.) Images and HTML docs should never reside in this tree.

        Images, HTML documents, etc., should reside in the non-executable side of the webserver which is mapped so that the content is merely displayed (and *NOT* executed). This tree is usually named "htdocs" (in the Unix world, in MS-IIS it's named something else).

        If you view the files statically (ie. via your filesystem), the configured limitations of the webserver mappings are not imposed, thus you can view the image successfully.

        Your wish is my commandline.
Re: <img> tag does not work in my perl/cgi code
by jkva (Chaplain) on Feb 23, 2008 at 21:49 UTC
    Just a wild guess... but I'd say your webserver is configured to treat files in /cgi-bin as scripts and can therefore not show it. But I might be completely wrong. In any case, cgi-bin is for scripts, not for images. Those belong in another folder , depending on your webserver's configuration.

    Best of luck!
      Thanks, it's a good guess, I will try to see the server configuration. The only thing is that I store other files like click count and others under /cgi-bin/ and all of them work. Could you comment this.
        It really depends on which program is in control when you are trying to look up /images/image.png. Sometimes /images/image.png is a URL, and sometimes it is a file path, and the two are most definately different, even though they look the same.

        Apache handles this internally, using a complex set of rules. /cgi-bin/ is one of these rules. Instead of looking in /var/www/cgi-bin/, Apache looks in /usr/lib/cgi-bin/ (under Debian). /images/ can be remapped in Apache too, perhaps leading to /var/images or something like that.

        However once your perl script has started, path lookups are handled as normal Unix path lookups (using the system PATH variable, plus any changes depending on the users settings).

        This is confusing, difficult, undocumented and something you have to learn when dealing with Unix. Or any operating system really. Web services are a confusing mash of programs, and figuring out which one has control at the critical moment is a big part of figuring out the bugs.

        Insight is found at the bottom of the cup.

        Dear Guys,

        I'm New to PERL, I'm trying to create a webpage with a Logo in PERL+CGI.

        I'm also facing the same problem.

        If you solved this, please share the information to help me.

        Here is my code:

        #!C:/Perl/bin/perl.exe use CGI; $q = new CGI; print "Content-type:text/html\n\n"; print '<HTML> <head></head> <body> <h1> <img alt="LOGO" src="LOGO.gif" alt="LOGO"/> My Name is SaRaVaNaN. </h1> </body> </HTML>';

        The HTML Styles are loading perfectly, & a 'X' box is showing instead of the image.

Re: <img> tag does not work in my perl/cgi code
by proceng (Scribe) on Feb 24, 2008 at 00:40 UTC
    if you change:
    (note the / before images) and store image.jpg in a images directory under your configured web root drive (on my lighttpd configuration it is:
    server.document-root = "/usr/local/var/www/"
    so image.jpg would have a real location of /usr/local/var/www/images/image.jpg) you should find that it works.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-05-30 16:03 GMT
Find Nodes?
    Voting Booth?

    No recent polls found