function export_and_download_layouts() { if (isset($_POST['export_and_download'])) { $nonce = $_POST["wp_nonce_export_layouts"]; if (WPDD_Utils::user_not_admin()) { die(__("You don't have permission to perform this action!", 'ddl-layouts')); } if (wp_verify_nonce($nonce, 'wp_nonce_export_layouts')) { $results = $this->export_for_download(); $sitename = sanitize_key(get_bloginfo('name')); if (!empty($sitename)) { $sitename .= '.'; } require_once WPDDL_TOOLSET_COMMON_ABSPATH . '/Zip.php'; if (class_exists('Zip')) { $dirname = $sitename . 'dd-layouts.' . date('Y-m-d'); $zipName = $dirname . '.zip'; $zip = new Zip(); $zip->addDirectory($dirname); foreach ($results as $file_data) { $zip->addFile($file_data['file_data'], $dirname . '/' . $file_data['file_name']); } $zip->sendZip($zipName); } } die; } }
$zip = new Zip(); // Archive comments don't really support utf-8. Some tools detect and read it though. $zip->setComment("Example Zip file.\nАрхив Комментарий\nCreated on " . date('l jS \of F Y h:i:s A')); // A bit of russian (I hope), to test UTF-8 file names. $zip->addFile("Привет мир!", "Кириллица имя файла.txt"); $zip->addFile("Привет мир!", "Привет мир. С комментарий к файлу.txt", 0, "Кириллица файл комментарий"); $zip->addFile("Hello World!", "hello.txt"); @$handle = opendir($fileDir); if ($handle) { /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if (strpos($file, ".php") !== false) { $pathData = pathinfo($fileDir . $file); $fileName = $pathData['filename']; $zip->addFile(file_get_contents($fileDir . $file), $file, filectime($fileDir . $file), NULL, TRUE, Zip::getFileExtAttr($file)); } } } // Add a directory, first recursively, then the same directory, but without recursion. // Naturally this requires you to change the path to ../test to point to a directory of your own. // $zip->addDirectoryContent("testData/test", "recursiveDir/test"); // $zip->addDirectoryContent("testData/test", "recursiveDir/testFlat", FALSE); //$zip->sendZip("ZipExample1.zip"); //$zip->sendZip("ZipExample1_€2,000.zip"); $zip->sendZip("ZipExample1_€2,000.zip", "application/zip", "ZipExample1_€2,000_utf8.zip"); ?>
<?php // Example. Zip all .html files in the current directory and send the file for Download. // Also adds a static text "Hello World!" to the file Hello.txt $fileDir = './'; ob_start(); // This is only to show that ob_start can be called, however the buffer must be empty when sending. include_once "Zip.php"; $fileTime = date("D, d M Y H:i:s T"); $zip = new Zip(); //$zip->setExtraField(FALSE); // The comment can only be ASCII, the Chinese characters fail here, and the Zip spec have no flags for handling that. $zip->setComment("Example 你好 Zip file.\nCreated on " . date('l jS \\of F Y h:i:s A')); $zip->addFile("你好 1", "hello 1.txt"); $zip->addFile("你好 1", "hello 2.txt", 0, "Hello 1"); $zip->addFile("你好 1", "hello 3.txt", 0, "Hello 你好"); $zip->addFile("你好 2", "你好 1.txt"); $zip->addFile("你好 2", "你好 2.txt", 0, "Hello 1"); $zip->addFile("你好 2", "你好 3.txt", 0, "Hello 你好"); $zip->addFile("你好 3", "你好/hello.txt"); $zip->addFile("你好 4", "你好/你好.txt"); $zip->sendZip("Zip.Test6.zip");
<?php // Example. Zip all .html files in the current directory and send the file for Download. $fileDir = './'; include_once("Zip.php"); $fileTime = date("D, d M Y H:i:s T"); $zip = new Zip(); $zip->setComment("Example Zip file.\nCreated on " . date('l jS \of F Y h:i:s A')); $zip->addFile("Hello World!", "hello.txt"); if ($handle = opendir($fileDir)) { /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if (strpos($file, ".html") !== false) { $pathData = pathinfo($fileDir . $file); $fileName = $pathData['filename']; $zip->addFile(file_get_contents($fileDir . $file), $file, filectime($fileDir . $file)); } } } $zip->sendZip("ZipExample1a.zip"); ?>
$zip->addFile(file_get_contents($fileDir . $file), $file, filectime($fileDir . $file), NULL, TRUE, Zip::getFileExtAttr($file)); } } } // Uses my Lipsum generator from https://github.com/Grandt/PHPLipsumGenerator if(file_exists('./LipsumGenerator.php')) { require_once './LipsumGenerator.php'; $lg = new com\grandt\php\LipsumGenerator(); $zip->openStream("big one3.txt"); for ($i = 1 ; $i <= 20 ; $i++) { $zip->addStreamData("Chapter $i\r\n\r\n" . $lg->generate(300, 2500) . "\r\n"); } $zip->closeStream(); } $zip->sendZip("ZipExample3.zip", "application/zip", "ZipExample3.zip"); // If non-fatal errors occured during execution, this will append them // to the end of the generated file. // It'll create an invalid Zip file, however chances are that it is invalid // already due to the error happening in the first place. // The idea is that errors will be very easy to spot. if (!empty($errors)) { echo "\n\n**************\n*** ERRORS ***\n**************\n\n$errors"; } function customError($error_level, $error_message, $error_file, $error_line) { global $errors; switch ($error_level) { case 1: $e_type = 'E_ERROR'; $exit_now = true; break; case 2: $e_type = 'E_WARNING'; break;