Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

pushing requested file

by filmo (Scribe)
on Feb 08, 2002 at 08:46 UTC ( #144063=categorized question: print w/replies, xml ) Need Help??
Contributed by filmo on Feb 08, 2002 at 08:46 UTC
Q&A  > CGI programming


Okay, so I've got a link in the page like this:
<a href="perl.cgi?random_id=23ljasdf09">
Which of course links to the correct file and pulls up the correct directory information from the database. perl.cgi then creates a URL string like this
$URL = "/base_directory/client/job/final.doc";
Where the 'final.doc' is the document refreneced by the 'random_id' in the original HREF link. (There are other checks in place, not shown here.)

Next, I want to 'push' that document to the user and have tried variations of:

print "Location:$URL";
And I end up with various results depending on the browsers. (some, on Windoz either open the file in Word or save it to disk; on Mac, it saves the file under the name "perl.cgi" instead of "final.doc" ??) What I'd really like is for the client to be able to click on the link and have the finished MS Word document saved to their disk (assuming they consent.) What's the best approach to this. I'm sure I must be doing something rather simple wrong. Thanks.

Answer: pushing requested file
contributed by gav^


use CGI; my $cgi = CGI->new; print $cgi->header(-location => "$URL");
I tested this on IE and it opens the word document straight into the browser window.

Hope this helps...


Answer: pushing requested file
contributed by abaxaba

Another approach might be this:

open (FILE, "/path/to/$URL"); binmode (FILE); print "\n\n"; while (<FILE>) { print; }
Answer: pushing requested file
contributed by silent11


print "Location:$URL\n\n";

Please (register and) log in if you wish to add an answer

  • 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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (8)
    As of 2020-08-03 12:49 GMT
    Find Nodes?
      Voting Booth?
      Which rocket would you take to Mars?

      Results (27 votes). Check out past polls.