print "Content-Type: application/octet-stream\n\n";
You can only use a single CRLF character as header separator. Here, you use two. Two CRLF character is used to separate headers from content.

After all, how can you have two Content-Type header? If what you have is a plain text file to send, you don't need that octet-stream. I think you want,

print "Content-Type: text/plain\n"; print "Content-Length: $filesize\n"; print "Content-disposition: attachment; filename=$filename\n\n"; open FILE, $filename or die "can't open $filename: $!\n"; print while <FILE>; close FILE;
Using \n as CRLF can be problematic. It's safer to use CGI or CGI::Simple, CRLF is handled automatically.
use CGI::Simple; use strict; use warnings; my $cgi = CGI::Simple->new; my $filename = '/usr/local/..../file.txt'; # assumed exists print $cgi->header( -type => 'text/plain', -attachment => $filename, -content_length => -s($filename), ); open FILE, $filename or die "Can't open $filename: $!\n"; print while <FILE>;

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!


In reply to Re: Not able to display 'save as dialog box' in browser by naikonta
in thread Not able to display 'save as dialog box' in browser by perlCrazy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.