Click to See Complete Forum and Search --> : Perl Binary file handling


akgalp
October 9th, 2008, 05:48 AM
hello all

please see the code below
i'm a newbie in perl.


use File::stat;

print "Content-type: image/jpg \n\n";
#print "Content-type: text/html\n\n";

my $buffer;
my $file = "1.jpg";
my $length = stat($file)->size;
#print "Content-length: $length \n\n";
open FN,$file;
binmode FN;
read FN, $buffer, $length;
print $buffer;
close FN;


i'm trying to open a jpg file and trying to send it to browser.
but the file arrives in browser as correpted (?).

(server indigoperl, apache 1.3.26,mod_perl 1.25 )

Pls help
thanks

mmetzger
October 9th, 2008, 08:23 AM
Your output is not set to handle binary data - it's being translated to ascii when it's sent.

Try adding this - I haven't fiddled with mod_perl in a long time but this should work...


open FN,$file;
binmode FN;
read FN, $buffer, $length;

#NEW LINE
binmode STDOUT;

print $buffer;
close FN;