Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

pushing requested file

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


Description:

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: www.mysite.com/$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^

or:

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

Hope this helps...

gav^

Answer: pushing requested file
contributed by abaxaba

Another approach might be this:

open (FILE, "/path/to/$URL"); binmode (FILE); print "Content-type:application-vnd.ms-word\n\n"; while (<FILE>) { print; }
hth...
Answer: pushing requested file
contributed by silent11

try

print "Location: www.mysite.com/$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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (7)
    As of 2014-12-25 22:20 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (163 votes), past polls