Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Force download -- Repost

by Kozz (Friar)
on Apr 03, 2004 at 03:27 UTC ( #342223=note: print w/replies, xml ) Need Help??


in reply to Force download -- Repost

Your main problem is that you're only outputting the header and not the contents of the file itself. If you're going to output your own mime-type header like this, you would then need to open the file in question (use binmode()) in chunks, outputting those chunks to the browser as they are read.
my $buffer; open(DOWNLOAD, "< /path/requested_file") or die "Could not read file: +$!"; binmode(DOWNLOAD); while( read(DOWNLOAD, $buffer, 4096) ){ print $buffer; } close(DOWNLOAD);
"Forcing a download" is really a function of the browser, and results from the browser's decision on how to handle the particuar mime type you send. You may want to also try "application/binary" in addition to the "application/octet-stream". In your code, I think that using 'join' is a bit of overkill when you can concatenate the strings as
my $load_file = $dl_file . $file;
Also, I would get rid of the start_html and end_html bit -- unnecessary, and I suppose could mess up your headers, too.

Replies are listed 'Best First'.
Re: Re: Force download -- Repost
by Anonymous Monk on Apr 03, 2004 at 03:52 UTC
    Thank you for your suggestions but it's still producing the same output as before. It enforces a DOWNLOAD/SAVE AS popup without the filename (but it pops up with the script name without the extension).

    I added your buffer and print codes and commented out the HTML headers. It didn't error out so I assume it could find the file, it's just not producing ANYTHING other than a popup without a file.

    Any other suggestions?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://342223]
help
Chatterbox?
[Corion]: choroba: I use spod5, which also has that support, and also implements its own kinda-make stuff
[haukex]: But that module I just linked to assumes that most verbatim blocks are runnable code, I have other modules where that's not the case, so there I just copy-and-paste the synopsis into the author tests...
[haukex]: not the most efficient, but then again, I don't have that many modules on CPAN :-)
[Corion]: haukex: Yes, but if it's only supposed to run on my machine, I can be far more liberal with how I extract the code etc.
[Corion]: haukex: Yes - I see the benefit of using Dist::Zilla for people with 150+ modules on CPAN, but I don't see it for myself, and I'm always put off from contributing to such modules because they require a lot of toolchain setup that I don't want to ...
[Corion]: ... spend time on if I only want to provide a short patch
[haukex]: Corion: Yes exactly, in the author tests I don't worry about portability as much, I also don't list the author tests' dependencies in Makefile.PL
[haukex]: I figure someone who wants to contribute will know how to install the missing modules ;-) Not the nicest way to go but I don't think many people are using my modules yet

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2017-02-27 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (385 votes). Check out past polls.