You are almost there, before you print the array to need to tell it the content type of the file in question. If its a gif

print "Content-type: image/gif\n\n";

Or if its an application:

print "Content-type: application/octet-stream\n\n";

There are some others, you should just search around for them.

To force a download you can do a couple of things.
1. Before your content header you can do this:

print "Content-disposition: attachment\n";

However I understand that doesn't work in some versions of IE. So the second thing you can do is pass your filename as though it were part of the path. Anything after the cgi filename is considered path info and is recognized as a parameter, however the browser thinks its just a path and downloads it with the correct filename and everything. If you are using CGI you can set it up like this:

my $cgi = new CGI; my $filename = $cgi->path_info();

When you call that with a path like this:

http://your-domain.com/cgi-bin/script.cgi/your_file.doc
$filename will have "/your_file.doc" in it, you can remove the leading slash, print out the type and the rest of the file your browser will simply download "your_file.doc"

Hope that helps
Chris

Lobster Aliens Are attacking the world!

In reply to Re: Binary output ot browser/force download? by cfreak
in thread Binary output ot browser/force download? by soffen

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.