Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > File downloads

Reply
Thread Tools

File downloads

 
 
Bigus
Guest
Posts: n/a
 
      02-25-2004
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

 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      02-25-2004
"Bigus" <> writes:

> 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/...tent-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/groups?thre...l-l.bham.ac.uk

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
Reply With Quote
 
 
 
 
Bigus
Guest
Posts: n/a
 
      02-26-2004
> > 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/...tent-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/groups?thre...l-l.bham.ac.uk


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


 
Reply With Quote
 
Alan J. Flavell
Guest
Posts: n/a
 
      02-26-2004
On Wed, 25 Feb 2004, Brian McCauley wrote:

> 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.

> http://ppewww.ph.gla.ac.uk/~flavell/...tent-type.html


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File downloads to client Gibby ASP .Net 3 06-24-2004 05:31 PM
Multiple file downloads Robert Scheer ASP .Net 3 02-09-2004 01:45 PM
Large File Downloads - Best method? Tim ASP .Net 2 01-20-2004 09:52 PM
Javascript breaks after client downloads file to disk Jeff Cooper ASP .Net 1 10-17-2003 12:54 PM
Large File Downloads PJ ASP .Net 0 08-25-2003 11:44 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57