CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003
    Location
    Gods own country, India
    Posts
    248

    Arrow Perl Binary file handling

    hello all

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

    Code:
    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

  2. #2

    Re: Perl Binary file handling

    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...

    Code:
    open FN,$file;
    binmode FN;
    read FN, $buffer, $length;
    
    #NEW LINE
    binmode STDOUT;
    
    print $buffer;
    close FN;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured