You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Michael Clarke <Mi...@ird.govt.nz> on 2002/03/01 01:17:49 UTC
zip files and downloading
The following exert has been edited to protect our data.
Story is that we are using a java program and embedded perl to query a database and get a list of files. Once the list has been obtained, we use the java application to zip the files, and thn we feed this zip file thru embededperl to the browser for the user to downlad. We use the approach shown in the following file, where we read the file into the $buffer and the print to OUT the contents of $buffer. We believe that either $buffer stops printing to OUT when it reaches a null string, or the server stops feeding $buffer to the browser when a null string is encountered.
Short question: Anyone got a simple script like ours (or modify ours) that handles feeding .zip files for download?
long question: Whats our fix? I have done a lot of reading around the site and the null string argument is one of the few solutions I have seen - I know this is a fix in v2.xxx but that is not feesable for us at the moment.
Much help appreciated in advance...
*snip*
[- use MYLIB; use CGI qw/:standard :html3 escape/;-]
[$ var $status $msg $file_hdl $filestate $version $offset $buffer $save_name $save_rp $save_type $name $filename
$]
[-
$escmode =0;
($save_name, $save_rp,$save_type) = split /:/, $fdat{'filelist'};
($status,$msg,$file_hdl,$filestate,$version) = MYLIB::view_file('1.1',$save_name,$save_rp,$save_type);
################################################################
# NOTE!!!!!!
# the above code is just noise, but what we do have is $file_hdl which points to a previously created
# zip file.
$filename="test.zip";
$http_headers_out{'Content-Disposition'} = ": attachment; filename=$filename";
$http_headers_out{'Content-type'}= 'x-application/octet-stream';
$http_headers_out{'Content-encoding'}='x-gzip';
while (read($file_hdl, $buffer, 1024) ) {
print OUT "$buffer";
}
close($file_hdl);
-]
*/snip*
Michael Clarke
IRD Open Systems Team
Level 4, Telecom House
13-27 Manners Street
Wellington
Phone: +64 (04) 8031423
Mobile: +64 021 455 218
email: michael.clarke@ird.govt.nz
email: mac@ird.govt.nz
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: zip files and downloading
Posted by Gerald Richter <ri...@ecos.de>.
>We believe that either $buffer stops printing to OUT when it reaches a null
string,
> or the server stops feeding $buffer to the browser when a null string is
encountered.
You must set $escmode = 0 to be able to send binary data. When $escmode = 0,
Embperl also handles null bytes correctly. Since you have done this already,
null bytes shouldn't be the issue, but your example code will insert some \n
before your binary data, because of the line breaks between the blocks,
better write it like the following:
[- use MYLIB; use CGI qw/:standard :html3 escape/;
-][$ var $status $msg $file_hdl $filestate $version $offset $buffer
$save_name $save_rp $save_type $name $filename
$][-
$escmode =0;
($save_name, $save_rp,$save_type) = split /:/, $fdat{'filelist'};
.....
You should also make sure you have _no_ trailing spaces or line feeds
Gerald
-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting
Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925131
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org