File downloads

B

Bigus

I have a directory outside of my web root on the web server and I have a
Perl script that presents a listing of the files in that directory to the
user, providing they have authenticated properly. I want the user to be able
to click on a filename and download the file as though it was in a web
directory.
I figure I might be able to do this by reading the file and then sending it
to the users browser with the print command, ie: printing the appropriate
content-type followed by the file data, but I don't know how I would deal
with the different types of file. Is there a generic content-type that I
could use for all files that would simply case the user's browser to present
them with a save dialog and they could then download it, or is there some
better way of doing all this?

Bigus
 
B

Brian McCauley

Bigus said:
I have a directory outside of my web root on the web server and I have a
Perl script that presents a listing of the files in that directory to the
user, providing they have authenticated properly. I want the user to be able
to click on a filename and download the file as though it was in a web
directory.
I figure I might be able to do this by reading the file and then sending it
to the users browser with the print command, ie: printing the appropriate
content-type followed by the file data, but I don't know how I would deal
with the different types of file. Is there a generic content-type that I
could use for all files that would simply case the user's browser to present
them with a save dialog and they could then download it,

That question is not only frequently asked but also not in any way
Perl related.

application/octet-stream should do this.

You can also give hints via the content-disposition header.

Some braindead browsers ignore the information given by the server.
That's even more off-topic here...

http://ppewww.ph.gla.ac.uk/~flavell/www/content-type.html
or is there some better way of doing all this?

Again this question (script mediated download) is frequently asked.

The answer is yes, and this question too is not specific to Perl as I explain
in...

http://groups.google.com/[email protected]

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
B

Bigus

I have a directory outside of my web root on the web server and I have a
That question is not only frequently asked but also not in any way
Perl related.

application/octet-stream should do this.

You can also give hints via the content-disposition header.

Some braindead browsers ignore the information given by the server.
That's even more off-topic here...

http://ppewww.ph.gla.ac.uk/~flavell/www/content-type.html


Again this question (script mediated download) is frequently asked.

The answer is yes, and this question too is not specific to Perl as I explain
in...

http://groups.google.com/[email protected]

Thanks for the info.. Mod_Perl is one area that has always looked a bit
daunting to a minor intellect like myself, so I've never gone beyond reading
the introduction to it without getting a headache and feeling dizzy. So, I
think I will persist with this content-type approach and Alan's article is
very lucid.

Regards
Bigus
 
A

Alan J. Flavell

That question is not only frequently asked but also not in any way
Perl related.

No disagreement there.
application/octet-stream should do this.

[Where "do this" means "recipient's browser will offer to download
the data to a file".]

Downloading to file is a possible action, and indeed probably the
safest and best-advised action for a browser to take in such a case;
but it's arguable that application/octet-stream is the one and only
explicit HTTP content-type that /could/ imply "recipient is allowed to
guess" (it's not very clearly codified in the specs, beyond the
implication that octet-stream is an unspecified bag of bytes).
You can also give hints via the content-disposition header.
Indeed.

Some braindead browsers ignore the information given by the server.

(for some fairly constructive value of the term "ignore". Since
you're presumably referring to that operating system component that
thinks it's a web browser from MS, it actually goes through
considerable contortions before deciding - as it does in the majority
of practical cases - to violate RFC2616 by disregarding the
server-provided content-type.)
That's even more off-topic here...

Yes; excuse me for just pointing up a couple of items that often cause
confusion and which I thought might have misled someone if they had
been left unremarked here.

well, I do my best; but it's a complex puzzle that the dominant vendor
has visited on us in flagrant disregard of the interworking
specifications.

Of course the bottom line is that knowing what you want to do - in
terms of an HTTP protocol interchange etc. - is of little relevance to
Perl and to comp.lang.perl.misc, but when the hon Usenaut has decided
what to do, then c.l.p.m would be a reasonable place to find out how
to do it in Perl.

cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top