Before we continue, I just want you to know that by "force download" I mean the DOWNLOAD and SAVE as box appears, not upload files to their computer without them knowing.

I have a directory of files containing nearly all types of files (sounds, images, text, html, exes) and I want to force a download for that link when they click on the link for that file. I've been told 'application/octet-stream' is how you force ANY file to download rather than load in the screen (like images typically load to screen, right?).

The link forces a download right now, but it tries to download the CGI script itself without the extension instead of the file I'm telling it to. It's requesting action on a file "filemanager" instead of let's say image.gif or sound.wav. Does anyone see where I went wrong? I am linking to in like <a href="filemanager.cgi?dl=$_">download!</a> and $_ does indeed contain what I expect it to. I've done testing to be sure my variable contains what it should, and it does.

Where did I go wrong?

# $dl_file is absolute path to uploaded directory where files are kept my $download = url_param('dl'); if ($download ne "") { if (exists $uploadedfiles{$download}) { my($file, $type, $time, $size) = split(/::/, $uploadedfiles{$down +load}); my $load_file = join("", $dl_file, $file); print header(-type=>'application/octet-stream', -attachment=>"$load_file", -expires=>'-1d'); print start_html); print end_html; exit; } else { print header, start_html("ERROR"); print qq(<center>Does not exist!</center>); print end_html; exit; } }

In reply to Force download -- Repost 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.