Example #1
0
$zip->openStream("big one3.txt");
$zip->addStreamData($chapter1."\n\n\n");
$zip->addStreamData($chapter1."\n\n\n");
$zip->addStreamData($chapter1."\n\n\n");
$zip->closeStream();

// For this test you need to create a large text file called "big one1.txt"
if (file_exists("big one1.txt")) {
	$zip->addLargeFile("big one1.txt", "big one2a.txt", 0, null, \PHPZip\Zip\Core\ZipUtils::getFileExtAttr("big one1.txt"));

	$fhandle = fopen("big one1.txt", "rb");
	$zip->addLargeFile($fhandle, "big one2b.txt");
	fclose($fhandle);
}

$zip->addDirectory("Empty Dir");

//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.
Example #2
0
// To use the new namespaces, you need a bootstrapper/autoloader, examples are provided here.
// 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) {
Example #3
0
// Archive comments don't really support utf-8. Some tools detect and read it though.
$zip->setComment("Example Zip file for Large file sets.\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->openStream("big one3.txt");
$zip->addStreamData($chapter1."\n\n\n");
$zip->addStreamData($chapter1."\n\n\n");
$zip->addStreamData($chapter1."\n\n\n");
$zip->closeStream();

$zip->addDirectory("Empty Dir");

$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;
	switch ($error_level) {