I'm working on a project that creates delimited files from a DB that need to be sent to the user via the browser. Currently I am testing this with ASCII CSV data, but eventually it will be delimited Kanji character data.
I have things working up to the point of creating the text file and initiating the download, but it simply returns the text to the browser.
My approach to this is pretty much lifted from
this node which seems to be what I want to do, but it's not working.
There was a
reply to that node which said to use "attachment" instead of "inline" for the Content-disposition but that doesn't seem to work either.
Also, I am not calling any other HTTP headers before this point.
I'm passing a fully pathed file handle to this sub:
sub download_file {
my ($filename) = @_;
my $filesize = -s $filename;
# print full header
print "Content-disposition: inline; filename=$filename\n";
print "Content-Length: $filesize\n";
print "Content-Type: application/octet-stream\n\n";
# open in binmode
open(READ,$filename) || die;
binmode READ;
# stream it out
binmode STDOUT;
while (<READ>) { print $_; }
close(READ);
# should always return true
return(1);
}
Once I get this working, I would like to try to stream the data directly from the data array from which the CSV file is created. Assuming that I can get the download pop-up dialog to function, I would think I should be able to do that. Yes?
Thanks.
-THRAK
www.polarlava.com