shedokan Posted August 12, 2008 Share Posted August 12, 2008 How can I compress a whole directory? I tried creating this, but doesn't works: <?php class gz{ function adddir($name) { $fr=$name; $this->datasec[]=$fr; $cdrec=$name; $this->ctrl_dir[]=$cdrec; } function addfile($data,$name) { $zdata=gzcompress($data); $fr=$name; $fr .=$zdata; $this->datasec[]=$fr; $cdrec=$name; $this->ctrl_dir[]=$cdrec; } function file() { $data=implode('',$this->datasec); $ctrldir=implode('',$this->ctrl_dir); return $data.$ctrldir; } } $gz=new gz(); header('Content-type: application/octet-stream'); header('Content-disposition: attachment; filename=test.gz'); $file[1]=implode('', file('index.php')); //$gz->adddir('dir/'); $gz->addfile($file[1],'index.php'); echo $gz->file(); ?> only says invalid archive. please help, I need it for backup. Quote Link to comment https://forums.phpfreaks.com/topic/119297-how-can-i-compress-a-whole-directory/ Share on other sites More sharing options...
ignace Posted August 12, 2008 Share Posted August 12, 2008 use zip (http://be.php.net/manual/en/ref.zip.php) instead of zlib just iterate over the directory and add your files using the addFile() method, i suggest you write a recursive function for this, because you probably want subdirectories to be included. other compression methods can be found here: http://be.php.net/manual/en/refs.compression.php Quote Link to comment https://forums.phpfreaks.com/topic/119297-how-can-i-compress-a-whole-directory/#findComment-614592 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.