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

I have a cgi program where I am using Image as -- print $q->img ({ -src => "../images/logo_1.jpg", -align=>"CENTER"  });

When I created the script in linux and ran it from linux localhost ,it works fine (shows image and other relevant output). while, same i moved to windows and when I access it via browser, image doesnt show up. (rest all output shows fine). even I tried using full path of image (by which I can open image from cmd prompt), still no luck. Please help.

  • Comment on Image doesnot display in perl cgi when moved code from linux to windows
  • Download Code

Replies are listed 'Best First'.
Re: Image doesnot display in perl cgi when moved code from linux to windows
by Ea (Chaplain) on Jul 23, 2015 at 08:40 UTC
    My first instinct is that it has something to do with where your image is located relative to the webserver root directory. Could you provide some more detail with regards to the url you're using to access the page, where the page and the image are in relation to the webserver root? You want to make sure that the image is being served through the webserver and not a file path.

    Sometimes I can think of 6 impossible LDAP attributes before breakfast.

      URL I am accesing is http://localhost/cgi-bin/index.cgi

      the code for this page is

      #!perl use DBI; use CGI::Carp "fatalsToBrowser"; use CGI; my $q = CGI->new(); print $q->header; print $q->img ({ -src => "C:/Apache24/images/tree.jpeg", -align=>"CENT +ER" }); print $q->start_html; print $q->start_form( -method=>"get" , -action => "form_1.cgi" , ); print $q->div( {-align=> 'center' , }, $q->br,$q->br,$q->submit ( - +value=> 'Add New Employee' , -name => 'action' ,) ); print $q->end_form; print $q->start_form( -method=>"post" , -action => "db_connect.cgi" , +); print $q->div( {-align=> 'center' , }, $q->br,$q->br,$q->submit ( - +value=> 'View All Employees' , -name => 'action' ,) ); print $q->end_form; print $q->start_form( -method=>"get" , -action => "db_insert.cgi" , ); print $q->div( {-align=> 'center' , }, $q->br,$q->br,$q->submit ( - +value=> 'Delete Employee' , -name => 'action' ,) ); print $q->end_form; print $q->end_html;

      Even if i give full image path , as given in above source code, it doesnt show up. while I can access same via command prompt

        saurabh220837:

        You're using "C:/Apache24/images/tree.jpeg" as the image source. I can guarantee you that that's not the URL that will access the file.

        As people have mentioned to you, you'll need to check the apache configuration to find out how to tell it where the image is.

        For example, if I set up a web server, I might configure it like this:

        Alias /images C:/Apache24/images/ DocumentRoot D:/CoolWebsiteProject/html Alias /cgi-bin D:/CoolWebsiteProject/bin

        So as far as the outside world is concerned "https://YourWebsite.com/images/tree.jpeg" would be the location that the outside world would use to access your image file. Similarly, "https://YourWebsite.com/cgi-bin/index.cgi" would be coming from D:/CoolwebsiteProject/bin. That's why you need to look at your configuration. Any time you're putting something like "C:/local/path/to/file" in an web page, you're doing it wrong.

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.

        Have you checked the webserver log for any errors?

        Using an absolute path on the file system doesn't look right, try specifying that path as relative to the DocumentRoot.

        In addition to the path location mentioned above, you are also printing the <img> tag outside of the <html> block. The generated HTML is not valid. Access the source of the resource present at your URL (see LWP::UserAgent or curl or even echo 'GET /my/url HTTP/1.0' | telnet hostname 80 and take a look at what is being generated.

        --MidLifeXis

Re: Image doesnot display in perl cgi when moved code from linux to windows
by BrowserUk (Patriarch) on Jul 23, 2015 at 08:40 UTC
      i guess yes.. my windows login has created image and all dirrectory
        my windows login

        Webservers don't usually run under the login id of a named individual.

        As they are normally configured to start at boot time, they usually run under a restricted access account.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.
        I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!