1--TEST-- 2ZipArchive::addGlob() method 3--CREDITS-- 4Sammy Kaye Powers <sammyk@sammykmedia.com> 5w/Kenzo over the shoulder 6#phptek Chicago 2014 7--EXTENSIONS-- 8zip 9--SKIPIF-- 10<?php 11if(!defined("GLOB_BRACE")) die ('skip'); 12?> 13--FILE-- 14<?php 15include __DIR__ . '/utils.inc'; 16$dirname = __DIR__ . '/oo_addglob_dir/'; 17$file = $dirname . 'tmp.zip'; 18 19@mkdir($dirname); 20copy(__DIR__ . '/test.zip', $file); 21touch($dirname . 'foo.txt'); 22touch($dirname . 'bar.baz'); 23 24$zip = new ZipArchive(); 25if (!$zip->open($file)) { 26 exit('failed'); 27} 28$options = array('add_path' => 'baz/', 'remove_all_path' => TRUE); 29if (!$zip->addGlob($dirname . '*.{txt,baz}', GLOB_BRACE, $options)) { 30 echo "failed 1\n"; 31} 32if (!$zip->addGlob($dirname . '*.{txt,baz}', GLOB_BRACE, $options)) { 33 echo "failed 2\n"; 34} 35$options['flags'] = 0; // clean FL_OVERWRITE 36if (!$zip->addGlob($dirname . '*.{txt,baz}', GLOB_BRACE, $options)) { 37 var_dump($zip->getStatusString()); 38} 39$options['flags'] = ZipArchive::FL_OVERWRITE; 40if (!$zip->addGlob($dirname . '*.{txt,baz}', GLOB_BRACE, $options)) { 41 echo "failed 3\n"; 42} 43if ($zip->status == ZIPARCHIVE::ER_OK) { 44 if (!verify_entries($zip, [ 45 "bar", 46 "foobar/", 47 "foobar/baz", 48 "entry1.txt", 49 "baz/foo.txt", 50 "baz/bar.baz" 51 ])) { 52 echo "failed\n"; 53 } else { 54 echo "OK"; 55 } 56 $zip->close(); 57} else { 58 echo "failed 4\n"; 59} 60?> 61--CLEAN-- 62<?php 63$dirname = __DIR__ . '/oo_addglob_dir/'; 64unlink($dirname . 'tmp.zip'); 65unlink($dirname . 'foo.txt'); 66unlink($dirname . 'bar.baz'); 67rmdir($dirname); 68?> 69--EXPECT-- 70string(19) "File already exists" 71OK 72