File downloads

Discussion in 'Perl Misc' started by Bigus, Feb 25, 2004.

  1. Bigus

    Bigus Guest

    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
     
    Bigus, Feb 25, 2004
    #1
    1. Advertising

  2. "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/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/groups?threadm=

    --
    \\ ( )
    . _\\__[oo
    .__/ \\ /\@
    . l___\\
    # ll l\\
    ###LL LL\\
     
    Brian McCauley, Feb 25, 2004
    #2
    1. Advertising

  3. Bigus

    Bigus Guest

    > > 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/groups?threadm=


    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
     
    Bigus, Feb 26, 2004
    #3
  4. 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/www/content-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
     
    Alan J. Flavell, Feb 26, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PJ

    Large File Downloads

    PJ, Aug 26, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    324
  2. Jeff Cooper
    Replies:
    1
    Views:
    402
    Jeff Cooper
    Oct 17, 2003
  3. Tim
    Replies:
    2
    Views:
    1,995
    Laidbak
    Jan 20, 2004
  4. Robert Scheer

    Multiple file downloads

    Robert Scheer, Feb 7, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    390
    Kevin Spencer
    Feb 9, 2004
  5. Gibby

    File downloads to client

    Gibby, Jun 24, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,375
    Brian Lowe
    Jun 24, 2004
Loading...

Share This Page