Example #1
0
<?php

$zip = new ZipArchive();
$ret = $zip->open('./banners.zip', ZipArchive::OVERWRITE);
if ($ret !== TRUE) {
    printf('Failed with code %d', $ret);
} else {
    $directory = realpath('.');
    $options = array('add_path' => ' ', 'remove_path' => $directory);
    $zip->addPattern('/\\.html$/', $directory, $options);
    $zip->close();
}
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=banners.zip');
header('Content-Length: ' . filesize('./banners.zip'));
readfile('./banners.zip');
<?php

$dirname = dirname(__FILE__) . '/';
include $dirname . 'utils.inc';
$file = $dirname . '__tmp_oo_addpattern.zip';
copy($dirname . 'test.zip', $file);
touch($dirname . 'foo.txt');
touch($dirname . 'bar.txt');
$zip = new ZipArchive();
if (!$zip->open($file)) {
    exit('failed');
}
$dir = realpath($dirname);
$options = array('add_path' => 'baz/', 'remove_path' => $dir);
if (!$zip->addPattern('/\\.txt$/', $dir, $options)) {
    echo "failed\n";
}
if ($zip->status == ZIPARCHIVE::ER_OK) {
    dump_entries_name($zip);
    $zip->close();
} else {
    echo "failed\n";
}
Example #3
0
<?php

$z = new ZipArchive();
$z->open('a.zip', ZIPARCHIVE::CREATE);
/* or 'remove_all_path' => 0*/
$options = array('remove_path' => '/home/pierre/cvs/gd/libgd/tests', 'add_path' => 'images/');
$found = $z->addPattern("/(\\.png)\$/i", "/home/pierre/cvs/gd/libgd/tests", $options);
var_dump($found);
$z->close();