Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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.


Comment on Re: Force download -- Repost
Select or Download Code
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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (14)
As of 2015-07-03 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (53 votes), past polls