in reply to Re^5: Not able to display an image in perl CGI
in thread Not able to display an image in perl CGI

The file system path will most likely not work - the -src path needs to be either relative to the web server root, or specially configured as a directory in the web server config.

One possible option is to do:

my $file = "/cgi-bin/PTF//WP_20140410_19_01_49_Pro.jpg";
which assumes that "/var/www" is the server root.

        What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
              -Larry Wall, 1992

Replies are listed 'Best First'.
Re^7: Not able to display an image in perl CGI
by aniammu (Novice) on Apr 30, 2014 at 05:22 UTC
    After changing the path also I am getting errors
    # perl image1 Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <img src="/cgi-bin/PTF//WP_20140410_19_01_49_Pro.jpg" alt="image" /> </body> </html> #
    # cat image1 #!/usr/bin/perl; use strict; use CGI ':standard'; use CGI::Carp 'fatalsToBrowser'; my $file = "/cgi-bin/PTF//WP_20140410_19_01_49_Pro.jpg"; print header, start_html('Test'), img({-src=>$file,-alt=>'image'}), end_html; #
    And the error is
    [Wed Apr 30 10:29:34 2014] [error] [client 10.142.205.193] (2)No such +file or directory: exec of '/var/www/cgi-bin/PTF/image1' failed [Wed Apr 30 10:29:34 2014] [error] [client 10.142.205.193] Premature e +nd of script headers: image1

    The above error is from server logs .. /var/log/httpd/error_log.

    Do we have any other logs which can help to resolve this issue
      my mistake - remove the ; on the first line
      #!/usr/bin/perl
      poj
        Now I can see that I not getting any error in Explorer, but the image is not displayed. ( One small icon has been displayed after executing the script )

        In erro_log

        [Wed Apr 30 12:27:07 2014] [error] [client 10.142.205.193] (8)Exec for +mat error: exec of '/var/www/cgi-bin/PTF/WP_20140410_19_01_49_Pro.jpg +' failed, referer: http://10.58.117.54/cgi-bin/PTF/image1 [Wed Apr 30 12:27:07 2014] [error] [client 10.142.205.193] Premature e +nd of script headers: WP_20140410_19_01_49_Pro.jpg, referer: http://1 +0.58.117.54/cgi-bin/PTF/image1