1--TEST-- 2ZipArchive::addPattern() method 3--CREDITS-- 4Sammy Kaye Powers <sammyk@sammykmedia.com> 5w/Kenzo over the shoulder 6#phptek Chicago 2014 7--SKIPIF-- 8<?php 9if(!extension_loaded('zip')) die('skip'); 10?> 11--FILE-- 12<?php 13include __DIR__ . '/utils.inc'; 14 15$dirname = __DIR__ . '/oo_addpattern_dir/'; 16$file = $dirname . 'tmp.zip'; 17 18@mkdir($dirname); 19copy(__DIR__ . '/test.zip', $file); 20touch($dirname . 'foo.txt'); 21touch($dirname . 'bar.txt'); 22 23$zip = new ZipArchive(); 24if (!$zip->open($file)) { 25 exit('failed'); 26} 27$dir = realpath($dirname); 28$options = array('add_path' => 'baz/', 'remove_path' => $dir); 29if (!$zip->addPattern('/\.txt$/', $dir, $options)) { 30 echo "failed\n"; 31} 32if ($zip->status == ZIPARCHIVE::ER_OK) { 33 if (!verify_entries($zip, [ 34 "bar", 35 "foobar/", 36 "foobar/baz", 37 "entry1.txt", 38 "baz/foo.txt", 39 "baz/bar.txt" 40 ])) { 41 echo "failed\n"; 42 } else { 43 echo "OK"; 44 } 45 $zip->close(); 46} else { 47 echo "failed3\n"; 48} 49?> 50--CLEAN-- 51<?php 52$dirname = __DIR__ . '/oo_addpattern_dir/'; 53unlink($dirname . 'tmp.zip'); 54unlink($dirname . 'foo.txt'); 55unlink($dirname . 'bar.txt'); 56rmdir($dirname); 57?> 58--EXPECT-- 59OK 60