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

In reply to Web Initiated File Download by THRAK

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.