Unable to display image using perl CGI

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zak200
    New Member
    • Nov 2013
    • 3

    Unable to display image using perl CGI

    Hi,
    I am trying to display image , but its not working.
    Code:
    	
    #!C:/Perl64/bin/perl.exe 
    print "Content-type: image/gif\n\n"; 
    print <<EOF; 
    <HTML> 
    <HEAD> 
    <TITLE> Coding Page </TITLE> 
    </Head> 
    <BODY> 
    <P>Image uploading 
     
    <a href="/cgi-bin/image.cgi?image=create_form.gif"> 
    <a href="/cgi-bin/image.cgi?image=en.gif"> 
    </BODY></HTML>   
     
    EOF 
    exit;
    I have tried image sourse tag also.
    Code:
    	
    #!C:/Perl64/bin/perl.exe 
     
    print "Content-type: image/gif\n\n"; 
    print <<HTML; 
    <html> 
    <head> 
    <title> A Simple Perl CGI </title> 
    </head> 
    <body> 
    <img src="en.jpg" width="225" height="225" /> 
    <h1>A Simple Perl CGI </h1> 
    </body> 
    HTML 
    exit;
    Can somebody guide me with this problem.

    Zulfi.
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    You're indicating the content time image/gif, but the content you're actually outputting is text/html. If you actually want to send an image, then you must send the contents of that image out after the header:

    Code:
    use File::Copy;
    print "Content-type: image/gif\n\n";
    copy "/path/to/image.gif", \*STDOUT;
    - Miller

    Comment

    Working...