1--TEST-- 2setCompressionName and setCompressionIndex methods 3--SKIPIF-- 4<?php 5if (!extension_loaded('zip')) die('skip'); 6?> 7--FILE-- 8<?php 9$tmpfile = __DIR__ . '/oo_setcompression.zip'; 10 11if (file_exists($tmpfile)) { 12 unlink($tmpfile); 13} 14 15// generate the ZIP file 16$zip = new ZipArchive; 17if ($zip->open($tmpfile, ZipArchive::CREATE) !== TRUE) { 18 exit('failed'); 19} 20$txt = file_get_contents(__FILE__); 21$zip->addFromString('entry1.txt', $txt); 22$zip->addFromString('entry2.txt', $txt); 23$zip->addFromString('dir/entry3.txt', $txt); 24$zip->addFromString('entry4.txt', $txt); 25$zip->addFromString('entry5.txt', $txt); 26$zip->addFromString('entry6.txt', $txt); 27$zip->addFromString('entry7.txt', $txt); 28 29var_dump($zip->setCompressionName('entry2.txt', ZipArchive::CM_DEFAULT)); 30var_dump($zip->setCompressionName('dir/entry3.txt', ZipArchive::CM_STORE)); 31var_dump($zip->setCompressionName('entry4.txt', ZipArchive::CM_DEFLATE)); 32 33var_dump($zip->setCompressionIndex(4, ZipArchive::CM_STORE)); 34var_dump($zip->setCompressionIndex(5, ZipArchive::CM_DEFLATE)); 35var_dump($zip->setCompressionIndex(6, ZipArchive::CM_DEFAULT)); 36 37if (!$zip->close()) { 38 exit('failed'); 39} 40 41 42// check the ZIP file 43$zip = zip_open($tmpfile); 44if (!is_resource($zip)) { 45 exit('failed'); 46} 47 48while ($e = zip_read($zip)) { 49 echo zip_entry_name($e) . ': ' . zip_entry_compressionmethod($e) . "\n"; 50} 51zip_close($zip); 52?> 53--CLEAN-- 54<?php 55$tmpfile = __DIR__ . '/oo_setcompression.zip'; 56unlink($tmpfile); 57?> 58--EXPECTF-- 59bool(true) 60bool(true) 61bool(true) 62bool(true) 63bool(true) 64bool(true) 65 66Deprecated: Function zip_open() is deprecated in %s on line %d 67 68Deprecated: Function zip_read() is deprecated in %s on line %d 69 70Deprecated: Function zip_entry_name() is deprecated in %s on line %d 71 72Deprecated: Function zip_entry_compressionmethod() is deprecated in %s on line %d 73entry1.txt: deflated 74 75Deprecated: Function zip_read() is deprecated in %s on line %d 76 77Deprecated: Function zip_entry_name() is deprecated in %s on line %d 78 79Deprecated: Function zip_entry_compressionmethod() is deprecated in %s on line %d 80entry2.txt: deflated 81 82Deprecated: Function zip_read() is deprecated in %s on line %d 83 84Deprecated: Function zip_entry_name() is deprecated in %s on line %d 85 86Deprecated: Function zip_entry_compressionmethod() is deprecated in %s on line %d 87dir/entry3.txt: stored 88 89Deprecated: Function zip_read() is deprecated in %s on line %d 90 91Deprecated: Function zip_entry_name() is deprecated in %s on line %d 92 93Deprecated: Function zip_entry_compressionmethod() is deprecated in %s on line %d 94entry4.txt: deflated 95 96Deprecated: Function zip_read() is deprecated in %s on line %d 97 98Deprecated: Function zip_entry_name() is deprecated in %s on line %d 99 100Deprecated: Function zip_entry_compressionmethod() is deprecated in %s on line %d 101entry5.txt: stored 102 103Deprecated: Function zip_read() is deprecated in %s on line %d 104 105Deprecated: Function zip_entry_name() is deprecated in %s on line %d 106 107Deprecated: Function zip_entry_compressionmethod() is deprecated in %s on line %d 108entry6.txt: deflated 109 110Deprecated: Function zip_read() is deprecated in %s on line %d 111 112Deprecated: Function zip_entry_name() is deprecated in %s on line %d 113 114Deprecated: Function zip_entry_compressionmethod() is deprecated in %s on line %d 115entry7.txt: deflated 116 117Deprecated: Function zip_read() is deprecated in %s on line %d 118 119Deprecated: Function zip_close() is deprecated in %s on line %d 120