From be2491b093b1f0ca430bede679ecbb670041e483 Mon Sep 17 00:00:00 2001 From: cassio Date: Tue, 2 Jul 2013 09:46:45 +0400 Subject: restructuring of boca's git --- src/fzip.php | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/fzip.php (limited to 'src/fzip.php') diff --git a/src/fzip.php b/src/fzip.php new file mode 100644 index 0000000..2a66722 --- /dev/null +++ b/src/fzip.php @@ -0,0 +1,78 @@ +. +//////////////////////////////////////////////////////////////////////////////// +//Last updated 21/jul/2012 by cassio@ime.usp.br +require_once('hex.php'); + +function create_zip($folder,$files,$destination,$msg=false,$zip=null) { + if(!function_exists('zip_open')) { + MSGError("Zip file error -- zip not installed (" . getFunctionName() .")"); + LogError("Zip file error -- zip not installed (" . getFunctionName() .")"); + } + $ds = DIRECTORY_SEPARATOR; + if($ds=="") $ds = "/"; + $dest=null; + if($zip == null) { + $zip = new ZipArchive(); + if($zip->open($destination,ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) { + return -1; + } + $dest=$destination; + $destination='.'; + } + foreach($files as $file) { + if($msg) + echo "Packing file " . $file . "\n"; + if(($pos = strrpos($file,$ds))!==false) + $file = substr($file,$pos+1); + if (is_dir($folder . $ds . $file) === true) { + $zip->addEmptyDir($file); + create_zip($folder . $ds . $file, + glob($folder . $ds . $file . $ds . '*'),$file,$msg,$zip); + } + else if (is_file($folder . $ds . $file) === true) { + $zip->addFile($folder . $ds . $file, $destination . $ds . $file); + } + } + if($dest != null) { + $zip->close(); + if(file_exists($dest)) return 1; else return 0; + } else return 1; +} + +function unzipstr($str,$txt='') { + $str = gzuncompress($str); + $pos = strrpos($str,"#"); + $test2 = substr($str,$pos+1); + $str = substr($str,0,$pos); + $test1 = myshorthash($str); + if($test1 != $test2) { + if($txt=='') + MSGError("Decompression error (" . getFunctionName() .")"); + LogError("Decompression error (" . getFunctionName() .",$txt)"); + return ""; + } + return $str; +} +function zipstr($str) { + if(!function_exists('gzcompress')) { + MSGError("Compression error -- zlib not installed (" . getFunctionName() .")"); + LogError("Compression error -- zlib not installed (" . getFunctionName() .")"); + } + return gzcompress($str . '#' . myshorthash($str)); +} +?> -- cgit v1.2.3