Ejemplo n.º 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");
    $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.
$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.
Ejemplo n.º 2
0
<?php

/*
 * A test to see if it was possible to recreate the result of
 *  Issue #7, if not the cause.
 * And a demnostration why the author of the script calling zip
 *  needs to be dilligent not to add extra characters to the output.
 */
include_once "ZipStream.php";
$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/test", "test");
return $zip->finalize();