This is a discussion on Script to simulate file downloading within the Linux Web Servers forums, part of the Web Server and Related Forums category; I'm putting together a custom document management system. (Don't ask why I don't use one of the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I'm putting together a custom document management system.
(Don't ask why I don't use one of the many open-source systems.) I'm trying to find a clean way to deal with different file types and versions. Users can upload files of any type (Word, Power Point, Open Office, PDF, ...) and I have to keep track of the versions. I came up with a scheme in which I store the documents with new file names produced from a unique document ID and version, for instance "112-1". I save the original uploaded file name in a database for future use. When someone downloads a file, I want the resulting file to have the original name, for instance "foobar.doc" instead of "112-1". My guess is that it should be possible to accomplish this by manipulation of the http headers, but I haven't figured it out yet. I have written a perl script that sends headers like this: Content-type: application/octet-stream Title: foobar.doc Content-Length: 26450 and then sends the content of the file. It arrives and is readable, but the name of the file produced is the name of the script, not foobar.doc. Is this approach going to work if I find the right incantation? (I haven't found a good description of what headers are sent when you a browser asks to download a file.) I could probably think of something else, such as making a temporary copy of the file on the server with the correct name. If I really wanted to get fancy, I could probably learn about MIME types and tweak the Content-type header too. Agh! |
|
|||
|
"Patrick Nolan" <pln@glast2.Stanford.EDU> wrote in message
news:slrnfdc6fb.v46.pln@glast2.Stanford.EDU... > When someone downloads a file, I want the resulting file to have > the original name, for instance "foobar.doc" instead of "112-1". > My guess is that it should be possible to accomplish this by > manipulation of the http headers, but I haven't figured it out yet. > I have written a perl script that sends headers like this: > Content-type: application/octet-stream > Title: foobar.doc > Content-Length: 26450 > > and then sends the content of the file. It arrives and is readable, > but the name of the file produced is the name of the script, not > foobar.doc. > This header should be the one you are after - Content-Disposition: attachment;filename="foobar.doc" |
| Thread Tools | |
| Display Modes | |
|
|