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

Try this simple test script

#!/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;
Update 1 : Corrected URL (thanks to NetWallah).
Update 2 : removed ; on first line
poj

Replies are listed 'Best First'.
Re^6: Not able to display an image in perl CGI
by NetWallah (Canon) on Apr 29, 2014 at 14:03 UTC
    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

      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