vivapl has asked for the wisdom of the Perl Monks concerning the following question:
Could someone please give me an example on how to download binary files(gzipped)?
Currently by clicking on a button on my webpage, I'm getting back a file of size 0. However when I intercept the content and save it into my temp dir, it's good. I'm just about clueless at this moment.
Here is my code:(I call &dl_user($somefile))
sub read_binary { local($fname) = @_; open(FILE, "<$fname") || return ''; while(<FILE>){ $spcontent .= $_; } close(FILE); $spcontent; } sub dl_user { ($loc)=@_; $filename = $loc; $filename =~ s/.+\/([^\/]+)$/$1/; $filename =~ s/.+\\([^\\]+)$/$1/; print "Content-Type: application/x-binary\n"; print"Content-Disposition:attachment;filename=$filename\n\n"; &read_binary($loc); }
Thanks in advance!
Edit by tye, title, remove extra P tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to offer binary files for download via CGI ?
by JamesNC (Chaplain) on Jul 22, 2003 at 21:51 UTC | |
|
Re: How to offer binary files for download via CGI ?
by sgifford (Prior) on Jul 22, 2003 at 21:48 UTC | |
by waswas-fng (Curate) on Jul 22, 2003 at 23:53 UTC | |
|
Re: How to offer binary files for download via CGI ?
by Zaxo (Archbishop) on Jul 22, 2003 at 20:51 UTC | |
by bobn (Chaplain) on Jul 22, 2003 at 23:49 UTC |