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

# cat image1 #!/usr/bin/perl use File::Copy; print "HTTP/0.9 200 OK\r\n"; print "Content-Type: image/jpeg\r\n"; print "\r\n"; copy "/var/www/cgi-bin/PTF//WP_20140410_19_01_49_Pro.jpg", \*STDOUT; #

After introducing Header information also i am getting the same error..

[Tue Apr 29 14:52:59 2014] [error] [client 10.142.236.15] malformed he +ader from script. Bad header=\xff\xd8\xff\xe1\xa7\xdcExif: image1

Replies are listed 'Best First'.
Re^3: Not able to display an image in perl CGI
by Anonymous Monk on Apr 29, 2014 at 09:49 UTC
    What webserver? Try
    #!/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;

    FWIW, its looking more and more like your webserver configuration is the problem

      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

        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

        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

        More information about this error may be available in the server error log.

        Have you checked the server error log?

        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.