// The changes to your Zip use are limited to two lines after that is in place. // Require your bootstrap.php, or the autoload.php, and change the class instantiation from nwe ZipStream( to // new \PHPZip\Zip\Stream\ZipStream( // The parameters are unchanged. require_once('bootstrap.php'); // include_once("ZipStream.php"); $zip = new \PHPZip\Zip\Stream\ZipStream('test.zip'); // $zip = new ZipStream("test.zip"); /* * As seen in the output, the above construct with a PHP end and start tag after * creating the ZipStream is a bad idea. The Zip file will be starting with a * space followed by the newline characters. */ $zip->addDirectory("test"); $zip->addDirectoryContent("testData" . DIRECTORY_SEPARATOR . "test","test"); $rv = $zip->finalize(); // If non-fatal errors occurred 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<pre>\n**************\n*** ERRORS ***\n**************\n\n$errors\n</pre>\n"; } 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;
//Dir test, using the stream option on $zip->addLargeFile $fileDir = './'; @$handle = opendir($fileDir); if ($handle) { /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if (($file != '.') && ($file != '..') && is_file($file)) { $zip->addLargeFile(($fileDir . $file), "dirTest/".$file, filectime($fileDir . $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->addDirectory("recursiveDir/"); $zip->addDirectoryContent("../test", "recursiveDir/test"); $zip->addDirectoryContent("../test", "recursiveDir/testFlat", FALSE); $zip->finalize(); // Mandatory, needed to send the Zip files central directory structure. // If non-fatal errors occurred 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<pre>\n**************\n*** ERRORS ***\n**************\n\n$errors\n</pre>\n"; } function customError($error_level, $error_message, $error_file, $error_line) { global $errors;