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