You can not force a browser to download your file. The Web protocols were designed to identify, via MIME Content-Type headers, what sort of content a data stream has, but not specify exactly what to do with it. Various HTML constructs ware designed to suggest, but not to force.

The only thing you can do is send an application/octet-stream; and hope that their browser will interpret this as a file for download. Many people configure their browsers in many different ways so there is no sure method. After all, the end decision rests with the browser/user - and thank goodnes for that.

If you really need to make sure that the file gets downloaded, you can try compressing/archiving the file in some way. Or you can try other methods; mainly a scripting language that might be able to do this for you.

You can always encourage the user to make use of browser features to save a file to disk, such as right-clicking in most browsers.

Cheers

- wil

In reply to (wil) Re: File Download from CGI Script by wil
in thread File Download from CGI Script by Anonymous Monk

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.