Ovid, thanks. Working from your code snippet I rolled it into the code below. Changed it to use CGI header generation and also passing a default file name.
Probably not good for everyone, but works well for what I'm doing. This worked in both IE5.5 & NS4.7x when I pass it a MIME of
$mime_type = "text/tab-separated-values\; charset=us-ascii";
One question, what does the localization of $/ do? I understand what they do independently, but why is this necessary?
sub download_file {
# REF: http://www.perlmonks.org/index.pl?node_id=110714&lastnode_id
+=3628
my ( $send_file, $send_name, $mime ) = @_;
die "$send_file does not exist." unless ( -e $send_file );
my $filesize = -s $send_file;
print $query->header(-type=>$mime,
-Content_disposition=>"attachment; fil
+ename=$send_name",
-Content_Length=>"$filesize"
);
# open in binmode
open READ, "< $send_file" or die "Cannot open $send_file for readi
+ng: $!";
binmode READ;
binmode STDOUT; # stream it out
{
local $/;
print <READ>;
}
close(READ);
return(1); # should always return true
}
-THRAK
www.polarlava.com
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.