Gossamer Forum
Home : General : Perl Programming :

print IMAGE to browser - question !

Quote Reply
print IMAGE to browser - question !
Hello !

This is the simple script use for print the image to browser - I don't know why it works on Unix but doesn't work on NT server :

#!/usr/bin/perl

$file ="/home/public_html/image/06.jpg"; # Unix path

# $file ="d:/myhost/image/06.jpg"; # use it if I run on NT server

if (open(IMAGE,"<$file")) {
print "Content-type: image/jpeg\n\n";
while (<IMAGE>) {
print;
}
}
else {
print "Content-type: text/plain\n\n Cannot open file $file\n";
}



Thanks for your help !

NewAge
Quote Reply
Re: [newage24] print IMAGE to browser - question ! In reply to
Use $! to find out why it doesn't work.
Quote Reply
Re: [RedRum] print IMAGE to browser - question ! In reply to
Hi RedRum !

I have tried to use

print $!;

but I didn't see any error message.

I got the error picture on the browser (the picture appear with X )

With Unix host I got the real picture on the browser but I don't know why the picture won't appear if I run the script on NT server. Frown

Thanks for your help !

N.A
Quote Reply
Re: [newage24] print IMAGE to browser - question ! In reply to
What about changing the forward slashes into backslashes?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [newage24] print IMAGE to browser - question ! In reply to
Try:

Code:
#!/path/to/perl

$file ="d:/myhost/image/06.jpg";

open IMG, "<$file" or die $!;
read IMG, my $img, -s IMG;
close IMG;

print "Content-type: image/jpeg\n\n";
print $img;

If that doesn't work I have one last idea.

Last edited by:

RedRum: Feb 1, 2002, 2:43 AM
Quote Reply
Re: [newage24] print IMAGE to browser - question ! In reply to
Is the file actually there? :-)

- wil
Quote Reply
Re: [newage24] print IMAGE to browser - question ! In reply to
Hi,

Let try the scripts below:

....
if (open(IMAGE, '/path/to/file') ) {
print "Content-type: image/jpeg\n\n";
($^O eq 'MSWin32') and binmode STDOUT;
binmode IMAGE;
my $buffer;
print $buffer while (read(IMAGE, $buffer , 500000));
close(IMAGE);

}

TheStone.

B.