/** * Comprime un archivo o directorio * Uso: UtilPsdf::comprimir('/home/usuario/foo/', '/home/usuario/foo.zip') * NOTA: Si se comprimirá un directorio este debe finalizar con la barra. * @param string $ruta Ruta del archivo/directorio a comprimir * @param string $zip_salida Ruta/nombre del zip a generar * @return boolean */ public static function comprimir($ruta, $zip_salida) { $zip = new Zipper(); if ($zip->open($zip_salida, ZIPARCHIVE::CREATE) === TRUE) { $zip->addFolder($ruta); $zip->close(); return true; } else { return false; } }
echo $nnode . '<br>'; if (is_dir($node)) { $this->addDir2($node); } elseif (is_file($node)) { $this->addFile($node); } } } } $zip = new Zipper(); $time = date('D-d-M-g-h-s', $_SERVER['REQUEST_TIME']); $res = $zip->open($_SESSION['folder'] . 'Backup-' . $time . '.zip', ZipArchive::CREATE); if ($res === TRUE) { $f = substr($_SESSION['folder'], 0, -1); $zip->addDir($f); $zip->close(); echo "压缩完成,文件保存为Backup-" . $time . ".zip<br>你可以 <a href=\"" . $meurl . "?op=home&folder=" . $_SESSION['folder'] . "\">查看文件夹</a> 或者 <a href=\"" . $meurl . "?op=home\">返回上次浏览的文件夹</a></div>\n"; } else { echo '<span class="error">压缩失败!</span>' . "</div>\n"; } mainbottom(); } else { printerror('此服务器上的PHP不支持ZipArchive,无法压缩文件!'); } } else { printerror("您没有选择文件"); } } if ($os !== 'windows') { if (@$_POST['action'] == '权限') { if (isset($_POST['select_item'])) {
public function exportProject($exportsettings, $dontsavesettings = false) { $userid = $this->getUserId(); $projectid = $this->getProjectId(); $data = $this->loadProjectData(); if (!$dontsavesettings) { $this->userdata->saveExportSettings($exportsettings); } // $theme = (strlen($exportsettings['styleTemplate'])) ? $exportsettings['styleTemplate'] : 'default'; $theme = "default"; $zip = new Zipper(); $filename = $this->projectpath . $data['path'] . "/" . $this->standardize($data['project']) . '.zip'; if (@file_exists($filename)) { @unlink($filename); } if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) { exit("cannot open <{$filename}>\n"); } $zip->addEmptyDir('images'); $zip->addEmptyDir('thumbs'); $zip->addEmptyDir('audio'); $zip->addEmptyDir('config'); $zip->addDir('./css'); $zip->addFile('./themes/' . $theme . '/css/styles.css', './css/styles.css'); $zip->addEmptyDir('icons'); $zip->addFilesFromDir('./themes/' . $theme . '/icons', './icons'); $zip->addDir('./js'); $zip->addFile('_index.html', '/index.html'); $zip->addFile('integration.html', '/integration.html'); $zip->addFile('_index_computer.html', '/_index_computer.html'); $zip->addFile('./flash/mmslides.swf', '/mmslides.swf'); $imageformat = strlen($exportsettings['width']) ? $exportsettings['width'] : "1024"; foreach ($data['data']['slides'] as $idx => $filedata) { if (array_key_exists('file', $filedata) && strlen($filedata['file'])) { $filepaths = array('1280' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "1280" . DIRECTORY_SEPARATOR . $filedata['file'], '1024' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "1024" . DIRECTORY_SEPARATOR . $filedata['file'], '800' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "800" . DIRECTORY_SEPARATOR . $filedata['file'], '640' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "640" . DIRECTORY_SEPARATOR . $filedata['file'], '480' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "480" . DIRECTORY_SEPARATOR . $filedata['file'], '320' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "320" . DIRECTORY_SEPARATOR . $filedata['file']); foreach ($filepaths as $filesize => $filepath) { if (@file_exists($filepath)) { $zip->addFile($filepath, '/images/' . $filesize . '/' . $filedata['file']); } $thumbpath = $this->projectpath . $data['path'] . "/thumbs/" . $filedata['file']; if (@file_exists($thumbpath)) { $zip->addFile($thumbpath, '/thumbs/' . $filedata['file'] . ".thumb.jpg"); } } } } $audiotrack = $data['data']['meta']['audio']; if (is_array($audiotrack) && strlen($audiotrack['file']) > 0) { $audiopath = $this->projectpath . $data['path'] . "/" . $audiotrack['file']; if (@file_exists($audiopath)) { $zip->addFile($audiopath, '/audio/' . $audiotrack['file']); } } $projectdata = $data; if (strlen($exportsettings['password'])) { $exportsettings['password'] = md5($exportsettings['password']); } $projectdata['slideshow'] = $exportsettings; $zip->addFromString('config/jsonconfig.js', json_encode($projectdata)); $zip->close(); return array('url' => $data['path'] . '/' . basename($filename)); }