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

Current code is as below, but still the same error.
#!/usr/bin/perl -- use File::Copy; use CGI qw( header ); my $file = "/var/www/cgi-bin/PTF//WP_20140410_19_01_49_Pro.jpg"; print header( -type => q{image/jpeg} , -nph => 1, -Content_length => - +s $file ); copy $file, \*STDOUT;
I tried both in firefox and IE. in the both browsers i am getting the below error..
Internal Server Error The server encountered an internal error or misconfiguration and was u +nable to complete your request. Please contact the server administrator, root@localhost and inform the +m of the time the error occurred, and anything you might have done th +at may have caused the error. More information about this error may be available in the server error + log. ---------------------------------------------------------------------- +---------- Apache/2.2.15 (Red Hat) Server at 10.58.117.54 Port 80

Replies are listed 'Best First'.
Re^5: Not able to display an image in perl CGI
by poj (Abbot) on Apr 29, 2014 at 11:37 UTC

    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
      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
Re^5: Not able to display an image in perl CGI
by Anonymous Monk on Apr 29, 2014 at 10:02 UTC

    Current code is as below, but still the same error.

    Then look at the other stuff (not the code), the server configuration ... gather version info wherever you can

      Please find below information...
      # /opt/apache-tomcat-7.0.32/bin/version.sh Using CATALINA_BASE: /opt/apache-tomcat-7.0.32 Using CATALINA_HOME: /opt/apache-tomcat-7.0.32 Using CATALINA_TMPDIR: /opt/apache-tomcat-7.0.32/temp Using JRE_HOME: /usr Using CLASSPATH: /opt/apache-tomcat-7.0.32/bin/bootstrap.jar:/op +t/apache-tomcat-7.0.32/bin/tomcat-juli.jar Server version: Apache Tomcat/7.0.32 Server built: Oct 3 2012 08:51:20 Server number: 7.0.32.0 OS Name: Linux OS Version: 2.6.32-279.19.1.el6.x86_64 Architecture: amd64 JVM Version: 1.6.0_24-b24 JVM Vendor: Sun Microsystems Inc. #
      Thanks in advance

        Please find below information...

        Now I'm even more convinced this is a configuration issue ... whatever it is

        Good luck

Re^5: Not able to display an image in perl CGI
by sn1987a (Curate) on Apr 29, 2014 at 12:23 UTC
    More information about this error may be available in the server error log.

    Have you checked the server error log?

      I have been checking /var/log/httpd/error_log. Do we have some other log other than this ?

        Do we have some other log other than this ?

        Hmm, apache is usually called http and not tomcat, so are those apache or tomcat logs? maybe :)

Re^5: Not able to display an image in perl CGI
by Discipulus (Canon) on Apr 29, 2014 at 10:27 UTC
    just for curiousity.. why you use non parsed header?
    -nph => 1,
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      I am not aware of the parser and non parser header. I will go through it now

      just for curiousity.. why you use non parsed header? -nph => 1,

      for the intended effect :D