Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

download hidden files

by hopalong (Initiate)
on Aug 19, 2002 at 21:43 UTC ( [id://191322]=perlquestion: print w/replies, xml ) Need Help??

hopalong has asked for the wisdom of the Perl Monks concerning the following question:

I'm having trouble creating a download script that is cross browser compatible. As it stands, it seems to work for .zip, .exe and .pdf, except the pdf doesn't work in MSIE 6+. MSIE just seems to do nothing when attempting a pdf download. My biggest problem has been Netscape spitting out a bunch of garbage code when attempting a download. Would appreciate any help. I have 2 files, the first one requests the second one. I'm not including the parse routine, trying to keep this short. Will post if you think that's the problem.

FILE 1:
#!/usr/bin/perl -wT $| = 1; $filename = "test.pdf"; print "Content-type: text/html\n\n"; print <<EOM; <FORM ACTION="b2.cgi?" METHOD="POST"> <INPUT TYPE="hidden" NAME="actiontype" VALUE="dload1/i"> <input type=hidden NAME="filename" value="$filename"> <INPUT TYPE="submit" VALUE="Download"> </form> EOM exit;
FILE 2:
#!/usr/bin/perl -wT $| = 1; $filepath = "/path/httpdocs/folder/"; $filename = "test.pdf"; &read_input; if ($data{'actiontype'} =~ /dload1/i) { print "Content-type: application/octet-stream\n" if ($filename =~ /\.e +xe$/); print "Content-type: application/zip\n" if ($filename =~ /\.zip$/); print "Content-type: application/pdf\n" if ($filename =~ /\.pdf$/); print "Content-type: application/x-pdf\n" if ($filename =~ /\.pdf$/); print "Content-Disposition: inline; filename=$filename\n"; print "Content-Description: File to download\n\n"; open (FILE, "$filepath$filename"); local ($/); $file = <FILE>; close (FILE); print $file; } exit;

Replies are listed 'Best First'.
Re: download hidden files
by krisahoch (Deacon) on Aug 19, 2002 at 22:26 UTC
    hopalong

    The problem you are encountering isn't one that you are going to be able to solve effectivly. The monkey wrench in your works is the fact that browsers to some extent dictate what is to be done with a certain file.

    I have my IE browser set up to open a pdf with adobe acrobat. My netscape browser simpy downloads it.

    Some people's browser may try to execute the pdf file (or in netscape's case) try to display the contents without the help of an application.

    Kristofer

    If at first you don't succeed, then skydiving is not for you
      So, the only feasible solution is to be sure that all files are in, for instance, .zip format. Even then it's not idiot proof, but reasonably safe?

        Pretty much. There is no really 'sure' way. Not everyone will have WinZip to unzip. It is tough to come up with the way you want to do it.

        Sorry to be such a harbinger


        Kristofer If at first you don't succeed, then skydiving is not for you
Re: download hidden files
by Chady (Priest) on Aug 20, 2002 at 06:32 UTC

    I think you'll get more of it to work if you change that line:

    print "Content-Disposition: inline; filename=$filename\n";
    to
    print "Content-Disposition: attachement; filename=$filename\n";

    cause, after all, you want to download the file, and not view it inline.


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/
Re: download hidden files
by rattusillegitimus (Friar) on Aug 20, 2002 at 14:12 UTC

    I'm not sure if this is a problem or not (I'm not at my home box where I can run tests), but I noticed that you seem to be sending two Content-type headers for filenames ending in .pdf:

    print "Content-type: application/pdf\n" if ($filename =~ /\.pdf$/); print "Content-type: application/x-pdf\n" if ($filename =~ /\.pdf$/);

    -rattus
    __________
    He seemed like such a nice guy to his neighbors / Kept to himself and never bothered them with favors
    - Jefferson Airplane, "Assassin"

      I tried it with both and only one pdf mime type. It didn't seem to make a difference for me. What does the "x-" indicate, as there are several mime types that use it?

      Don't know why I'd decided on inline, (thought I read a definition), but "attachment" makes more sense. Again though, it didn't make any difference for my setup.

      Also, if this can't really be accomplished, how does Download.com do it without fail? Do they just assume no one is stupid enough to set their browsers to run executables?

      Thanks for everyone's help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://191322]
Approved by ChemBoy
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2024-04-19 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found