in reply to Image doesnot display in perl cgi when moved code from linux to windows

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.
  • Comment on Re: Image doesnot display in perl cgi when moved code from linux to windows

Replies are listed 'Best First'.
Re^2: Image doesnot display in perl cgi when moved code from linux to windows
by saurabh220837 (Initiate) on Jul 23, 2015 at 09:01 UTC

    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