Forum Moderators: coopster

Message Too Old, No Replies

Zip Download A Folder

outputs as if being read

         

WhosAWhata

10:16 pm on May 14, 2004 (gmt 0)

10+ Year Member



the following code is intended to download a folder (it is a modified verion of some code i foun on another site

the problem is that instead of sending a zip file, it echo's that character mix you would see if you opened a zip file in notepad

any idea's on how to fix it, or a better script?


[quote]<?
function replace_ampersand($file, $bool){
if($bool==true){
return str_replace("&", "@@@", $file);
}else{
return str_replace("@@@", "&", $file);
}
}
session_start();
$myfolder = "MYFOLDER"; //folder to download
$folder = replace_ampersand($myfolder, false);
$download_file = "download[".preg_replace("#[^A-Za-z,0-9,=]#", "_", $myfolder)."].zip";
$systemcall = "/usr/bin/zip -r /tmp/$download_file $folder";
@exec($systemcall);
header("Content-disposition: attachment; filename=$download_file");
header("Content-type: application/octetstream");
header("Pragma: no-cache");
header("Pragma: public");
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Expires: 0");
$client=getenv("HTTP_USER_AGENT");
$size = filesize("/tmp/$download_file");
header("Content-Length: $size");
$hdl = fopen("/tmp/$download_file" , "r");
fpassthru($hdl);
@unlink("/tmp/$download_file");
?>
[/quote]

Netizen

10:09 am on May 16, 2004 (gmt 0)

10+ Year Member



I think you should do two things:

$hdl = fopen("/tmp/$download_file" , "r");

should be

$hdl = fopen("/tmp/$download_file" , "rb");

to be safer.

And you have a typo in

header("Content-type: application/octetstream");

which should be

header("Content-type: application/octet-stream");

(missing the hyphen in octet-stream)