Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: File Download

by guice (Scribe)
on Apr 26, 2000 at 08:30 UTC ( #9169=note: print w/ replies, xml ) Need Help??


in reply to File Download

The only way around that is to redirect the browser to the location of the file. The only reason the browser is showing the script name as the name of the file is cause it's the script that it's actually sending the download to the browser. From what the browser sees, it doesn't know it's downloading another file.

-- philip
We put the 'K' in kwality!


Comment on Re: File Download
RE: Re: File Download
by BBQ (Deacon) on Apr 26, 2000 at 22:00 UTC
    Not necessarily... All you need is for the httpd daemon to have read access on the file. I took care of the paths, filenames, sizes, etc by using this little snippet:
    sub DownloadFile { # $filepath is the directory # $filename is the name of the file my ($filepath,$filename) = @_; chdir($filepath) || return(0); my $filesize = -s $filename; # print full header print "Content-disposition: inline; filename=$filename\n"; print "Content-Length: $filesize\n"; print "Content-Type: application/octet-stream\n\n"; # open in binmode open(READ,$filename) || die; binmode READ; # stream it out binmode STDOUT; while (<READ>) { print; } close(READ); # should always return true return(1); }
    I hope that's useful. It has a few extra steps that aren't reeeaalllly needed, but its nice to be on the safe side.

    Cheers!

      The crucial part is the "Content-disposition" parameter.

      Incidentally, you should use
      Content-disposition: attachment; filename=file

      Instead of "inline" if you really want the save-as box to pop up. It probably won't make any difference, but it could if the user has a program set up to handle the content-type you're returning (for example, if you're returning a pdf file).

      Incidentally, the RFC on HTTP/1.1 only defines behavior with "attachment". (And that only in an appendix under "Additional Features")

        I had no idea that inline wasn't in the RFC. To be perfectly honest, I haven't even read it. I got the full header by ripping it off a bare telnet GET request and examining the response. I saw a CGI app that did what I wanted (I *think* its the download app at e.themes.org) and tried to mime what it was doing.

        One of those things that happen outta mere curiosity...
      could elaborate on how to implement this? thanks! fromsir

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://9169]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-07-29 01:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls