Your image problem probably has nothing to do with your perl program. It's probably a permissions problem. If you want to have perl display your image, it'd look more like this, but you wouldn't normally do this since having apache (or IIS) pick up perl and an image gets kindof heavy. If you want to print images, consider FCGI or mod_perl or something to keep perl picked up.
open my $file "<", $image_file or die "grr: $!"; # (You shouldn't print the header manually if you use CGI) print "Content-type: image/gif\n\n"; print $_ while <$file>;
Other notes: use strict and use warnings. Not using them will cause you trouble eventually. Also consider using a template package like HTML::Template. Also, don't load CGI if you're not going to use it for something. It's pretty big.
use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); my $cgi = CGI->new; print $cgi->header; # use $cgi->header("image/gif") for gifs print $cgi->start_html; print $cgi->table( $cgi->Tr( $cgi->td([ $cgi->img({src=>"blarg"}) )));
-Paul
In reply to Re: Display an image with a CGI program?
by jettero
in thread Display an image with a CGI program?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |