Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: File Download

by guice (Scribe)
on Apr 26, 2000 at 08:30 UTC ( [id://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!

Replies are listed 'Best First'.
RE: Re: File Download
by BBQ (Curate) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://9169]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-19 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found