Here is how I did something very similar for downloading PowerPoint files. I had a collection of PPT presentations and users could select which one they wished to download. Accept a form by cgi, get the name of the file requested, load the file, build any downlaod filename you like, return the appropriate disposition header, download the file.

Disposition headers are very important when doing this. You can force the file to open in different ways. In this example, I'm forcing PPT to open the file in PPT outside of the browser and in slideshow mode. (If I recall correctly - it's a while since I looked at this system in action.)

Obviously you'll write a much more elegant file-request-to-filename converter than the trash I've included here for this example.

$presentation_1 = "./mypath/my_file_1"; $presentation_2 = "./mypath/my_file_2"; $presentation_3 = "./mypath/my_file_3"; $download_filetype = ".pps"; #get_and_process_form; my $query = new CGI; @form_field_names = $query->param; foreach $field (@form_field_names) { $form_values{$field} = $query->param($field); } $request = $form_values{'report'}; if ($request eq "aaaa") {$presentation = $presentation_1;} elsif ($request eq "bbbb") {$presentation = $presentation_2;} else {$presentation = $presentation_3;} open(FILE, $presentation) or dienice("cannot open file $presentation : + $_[0] $!"); @LINES = <FILE>; close(FILE); $filename = join('_', $form_values{'report'}, $form_values{'language'} +, $form_values{'year'}); $filename = join('', $filename, $download_filetype); print "Content-type: application/vnd.ms-powerpoint\n"; print "Content-Disposition: attachment; filename=$filename\n\n"; for $i (0..$#LINES) { print $LINES[$i]; }

In reply to Re: File downloader by punch_card_don
in thread File downloader 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.