/** * Compress file as zip using pclzip library (thanhnv - use other lib now :D) * * @param $zipFile string path to store zip file * @param $path {string | array()} path to file or directory to zip * @param $rmPath boolean do not add full path to archive * * @return boolean true if success, false if failure */ function zip($zipFile, $path, $rmPath = false) { $oZip = new CreateZipFile(); if (!is_array($path)) { $paths[] = $path; } else { $paths = $path; } foreach ($paths as $path) { if (JFile::exists($path)) { $oZip->addDirectory($outputDir); $fileContents = file_get_contents($path); $oZip->addFile($fileContents, basename($path)); } elseif (JFolder::exists($path)) { $outputDir = str_replace(array(dirname($path), DS, '/'), '', $path) . DS; $oZip->zipDirectory($path, $outputDir); } } $out = JFile::write($zipFile, $oZip->getZippedfile()); return $out; }
/** * Compress file as zip using pclzip library (thanhnv - use other lib now :D) * * @param $zipFile string path to store zip file * @param $path {string | array()} path to file or directory to zip * @param $rmPath boolean do not add full path to archive * * @return boolean true if success, false if failure */ public static function zip($zipFile, $path, $rmPath = false) { $oZip = new CreateZipFile(); if (!is_array($path)) { $paths[] = $path; } else { $paths = $path; } foreach ($paths as $path) { if (is_file($path)) { $oZip->addDirectory($outputDir); $fileContents = file_get_contents($path); $oZip->addFile($fileContents, basename($path)); } elseif (is_dir($path)) { $outputDir = str_replace(array(dirname($path), DS, '/'), '', $path) . DS; $oZip->zipDirectory($path, $outputDir); } } $fp = fopen($zipFile, "wb"); $out = fwrite($fp, $oZip->getZippedfile()); fclose($fp); return $out; }