Zand Php Cake Php

Posted by : Jenny Homez
Zip files and download HELP
Hi All,

I want to zip a bundle of files and
download. Files are stored in my server. Dont want to store the zip
file. I am using zend framework.

Plz plz help me



regards,

basiL -  b - thoppiL
 
 
Posted by : Robert Gonzalez
Re : Zip files and download HELP
Not sure if it will help you, but have you checked the manual? Particularly the section about Zip?
 
 
Posted by : C.
Re : Zip files and download HELP
You've got way too much time to spend on this stuff Jenny.



I'd have just gone with



$cmd='/usr/bin/zip -c $zipfile ' . implode(' ',

$list_of_files_to_add);

echo `$cmd`;
 
 
Posted by : j.r.fish
Re : Zip files and download HELP
why don't you use the ZipArchive class? it works like a charm
http://www.php.net/manual/en/class.ziparchive.php
 
 
Posted by : Basil B Thoppil
Re : Zip files and download HELP
<?php
class zipfile
{
var $datasec = array();
var $ctrl_dir = array();
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\
x00";
var $old_offset = 0;

function add_dir($name) {
$name = str_replace("", "/", $name);


$fr = "\x50\x4b\x03\x04";
$fr .= "\x0a\x00";
$fr .= "\x00\x00";
$fr .= "\x00\x00";
$fr .= "\x00\x00\x00\x00";

$fr .= pack("V",0);
$fr .= pack("V",0);

$fr .= pack("V",0);
$fr .= pack("v", strlen($name) );
$fr .= pack("v", 0 );
$fr .= $name;
$fr .= pack("V", 0);
$fr .= pack("V", 0);
$fr .= pack("V", 0);


$this -> datasec[] = $fr;
$new_offset = strlen(implode("", $this->datasec));
$cdrec = "\x50\x4b\x01\x02";
$cdrec .= "\x00\x00";
$cdrec .= "\x0a\x00";
$cdrec .= "\x00\x00";

$cdrec .= "\x00\x00";
$cdrec .="\x00\x00\x00\x00";
$cdrec .= pack("V",0);
$cdrec .= pack("V",0);
$cdrec .= pack("V",0);
$cdrec .= pack("v", strlen($name) );

$cdrec .= pack("v", 0 );
$cdrec .= pack("v", 0 );
$cdrec .= pack("v", 0 );
$cdrec .= pack("v", 0 );
$ext = "\x00\x00\x10\x00";
$ext = "\xff\xff\xff\xff";

$cdrec .= pack("V", 16 );
$cdrec .= pack("V", $this -> old_offset );
$cdrec .= $name;

$this -> ctrl_dir[] = $cdrec;
$this -> old_offset = $new_offset;
return;
}

function add_file($data, $name) {

$fp = fopen($data,"r");
$data = fread($fp,filesize($data));
fclose($fp);
$name = str_replace("", "/", $name);
$unc_len = strlen($data);
$crc = crc32($data);
$zdata = gzcompress($data);

$zdata = substr ($zdata, 2, -4);
$c_len = strlen($zdata);
$fr = "\x50\x4b\x03\x04";
$fr .= "\x14\x00";
$fr .= "\x00\x00";
$fr .= "\x08\x00";
$fr .= "\x00\x00\x00\x00";

$fr .= pack("V",$crc);
$fr .= pack("V",$c_len);
$fr .= pack("V",$unc_len);
$fr .= pack("v", strlen($name) );
$fr .= pack("v", 0 );
$fr .= $name;
$fr .= $zdata;

$fr .= pack("V",$crc);
$fr .= pack("V",$c_len);
$fr .= pack("V",$unc_len);

$this -> datasec[] = $fr;
$new_offset = strlen(implode("", $this->datasec));


$cdrec = "\x50\x4b\x01\x02";
$cdrec .="\x00\x00";
$cdrec .="\x14\x00";
$cdrec .="\x00\x00";
$cdrec .="\x08\x00";
$cdrec .="\x00\x00\x00\x00";
$cdrec .= pack("V",$crc);

$cdrec .= pack("V",$c_len);
$cdrec .= pack("V",$unc_len);
$cdrec .= pack("v", strlen($name) );
$cdrec .= pack("v", 0 );
$cdrec .= pack("v", 0 );
$cdrec .= pack("v", 0 );

$cdrec .= pack("v", 0 );
$cdrec .= pack("V", 32 );
$cdrec .= pack("V", $this -> old_offset );

$this -> old_offset = $new_offset;

$cdrec .= $name;
$this -> ctrl_dir[] = $cdrec;

}

function file() {
$data = implode("", $this -> datasec);
$ctrldir = implode("", $this -> ctrl_dir);

return
$data .
$ctrldir .
$this -> eof_ctrl_dir .
pack("v", sizeof($this -> ctrl_dir)) .

pack("v", sizeof($this -> ctrl_dir)) .
pack("V", strlen($ctrldir)) .
pack("V", strlen($data)) .
"\x00\x00";
}
}

// Test this class
$zipTest = new zipfile();

$zipTest->add_dir("image/");
$zipTest->add_file("showtext.php", "showtext.php");
$zipTest->add_file("style.css", "style.css");
$zipTest->add_file("index.php", "index.php");

$zipTest->add_file("image/image1.jpg", "image/image1.jpg");
$zipTest->add_file("image/image2.jpg", "image/image2.jpg");
// Return Zip File to Browser
Header("Content-type: application/octet-stream");

Header ("Content-disposition: attachment; filename=indiacom.zip");
echo $zipTest->file();

// Alternatively, you can write the file to the file system and provide a link:
/*
$filename = "output.zip";

$fd = fopen ($filename, "wb");
$out = fwrite ($fd, $zipTest -> file());
fclose ($fd);

echo "Click here to download the new zip file.";
*/

?>
 
 
If you have the better reply, then send it to us. We will display your reply after the approval.
Name : 
Email Id :   
Reply :