public function admin_export($id = null) { if (!$id) { $this->notice('invalid'); } $this->Template->recursive = -1; $template = $this->Template->read(array('name', 'description', 'author', 'header', 'footer'), $id); if (empty($template)) { $this->notice('invalid'); } $pattern = "/src=[\\\"']?([^\\\"']?.*(png|jpg|gif|jpeg))[\\\"']?/i"; preg_match_all($pattern, $template['Template']['header'], $images); $path = TMP . 'cache' . DS . 'newsletter' . DS . 'template' . DS . $template['Template']['name']; $Folder = new Folder($path, 0777); $slash = $Folder->correctSlashFor($path); App::import('File'); App::import('Folder'); $File = new File($path . DS . 'template.xml', true, 0777); $imageFiles = array(); if (!empty($images[1])) { foreach ($images[1] as $img) { $img = str_replace('/', $slash, $img); $img = str_replace('\\', $slash . $slash, $img); $imageFiles[] = $img; if (is_file(APP . 'webroot' . $img)) { $Folder->create(dirname($path . $img), 0777); $File->path = APP . 'webroot' . $img; $File->copy(dirname($path . $img) . DS . basename($img)); } } } $xml['template']['name'] = 'Infinitas Newsletter Template'; $xml['template']['generator'] = 'Infinitas Template Generator'; $xml['template']['version'] = $this->version; $xml['template']['template'] = $template['Template']['name']; $xml['template']['description'] = $template['Template']['description']; $xml['template']['author'] = $template['Template']['author']; $xml['data']['header'] = $template['Template']['header']; $xml['data']['footer'] = $template['Template']['footer']; $xml['files']['images'] = $imageFiles; App::Import('Helper', 'Xml'); $Xml = new XmlHelper(); $File->path = $path . DS . 'template.xml'; $File->write($Xml->serialize($xml)); App::import('Vendor', 'Zip', array('file' => 'zip.php')); $Zip = new CreateZipFile(); $Zip->zipDirectory($path, null); $File = new File($path . DS . 'template.zip', true, 0777); $File->write($Zip->getZippedfile()); $this->view = 'Media'; $params = array('id' => 'template.zip', 'name' => $template['Template']['name'], 'download' => true, 'extension' => 'zip', 'path' => $path . DS); $this->set($params); $Folder = new Folder($path); $Folder->read(); $Folder->delete($path); }
/** * 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; }
<?php $fileToZip = "License.txt"; $fileToZip1 = "CreateZipFileMac.inc.php"; $fileToZip2 = "CreateZipFile.inc.php"; $directoryToZip = "./"; // This will zip all the file(s) in this present working directory $outputDir = "/"; //Replace "/" with the name of the desired output directory. $zipName = "test.zip"; include_once "CreateZipFile.inc.php"; $createZipFile = new CreateZipFile(); /* // Code to Zip a single file $createZipFile->addDirectory($outputDir); $fileContents=file_get_contents($fileToZip); $createZipFile->addFile($fileContents, $outputDir.$fileToZip); */ //Code toZip a directory and all its files/subdirectories $createZipFile->zipDirectory($directoryToZip, $outputDir); $rand = md5(microtime() . rand(0, 999999)); $zipName = $rand . "_" . $zipName; $fd = fopen($zipName, "wb"); $out = fwrite($fd, $createZipFile->getZippedfile()); fclose($fd); $createZipFile->forceDownload($zipName); @unlink($zipName);
// Sollen Dateinnamen im Zip die Pfade beinhalten? if ($_GET['incp'] == 'y') { $incp = true; } else { $incp = false; } $outputDir = "/"; //Replace "/" with the name of the desired output directory. $path_array = explode("/", $directoryToZip); $zipName = $path_array[count($path_array) - 2]; $rand = md5(microtime() . rand(0, 999999)); $zipName = $zipName . "_" . $rand . ".zip"; include_once "./include/functions.php"; include_once "./include/zipbuilder.php"; //include_once("./include/zip_withfile.php"); $createZipFile = new CreateZipFile(true); /* // Code to Zip a single file $createZipFile->addDirectory($outputDir); $fileContents=file_get_contents($fileToZip); $createZipFile->addFile($fileContents, $outputDir.$fileToZip); */ //Code toZip a directory and all its files/subdirectories $createZipFile->zipDirectory($directoryToZip, $outputDir, $zipName); //$createZipFile->zipDirectory($directoryToZip,$outputDir); //$createZipFile->sendZip($zipName); $createZipFile->forceDownload($zipName); unlink($zipName); //$fd=fopen($zipName, "wb"); //$out=fwrite($fd,$createZipFile->getZippedfile()); //fclose($fd);
public function actionBackup() { Yii::import('application.extensions.yii-zip.CreateZipFile'); $createZip = new CreateZipFile(); //$createZip->zipDirectory('../ims/protected', ''); $createZip->zipDirectory('protected/data', ''); $date = date('d-F-y-h-i'); $zipFileName = $date . '_ims_backup.zip'; $handle = fopen($zipFileName, 'wb'); $out = fwrite($handle, $createZip->getZippedFile()); fclose($handle); $createZip->forceDownload($zipFileName); @unlink($zipFileName); }
while ($i < count($dir)) { foreach ($dir as $d) { $dir_wpath = $usr_path . $d; if (is_empty($dir_wpath)) { rmdir($dir_wpath); } else { foreach (get_files($dir_wpath) as $f) { if (file_exists($backup_wpath)) { unlink($dir_wpath . '/' . $f); } else { $outputDir = "backup/"; //Replace "/" with the name of the desired output directory. $zipName = "backup_" . date('Ymd_His') . ".zip"; $zip = new CreateZipFile(); //Code toZip a directory and all its files/subdirectories $zip->zipDirectory("upload"); $rand = md5(microtime() . rand(0, 999999)); $backup_wpath = $outputDir . $zipName; $fd = fopen($backup_wpath, "wb"); $out = fwrite($fd, $zip->getZippedfile()); fclose($fd); #$zip->addFile($dir_wpath, $f); #$zip->save($backup_wpath); } } } } $i++; } /** * Get all files in directory