1--TEST-- 2setCompressionName and setCompressionIndex methods 3--SKIPIF-- 4<?php 5if (!extension_loaded('zip')) die('skip'); 6?> 7--FILE-- 8<?php 9$tmpfile = dirname(__FILE__) . '/__tmp_oo_set_compression.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 = dirname(__FILE__) . '/__tmp_oo_set_compression.zip'; 56unlink($tmpfile); 57?> 58--EXPECT-- 59bool(true) 60bool(true) 61bool(true) 62bool(true) 63bool(true) 64bool(true) 65entry1.txt: deflated 66entry2.txt: deflated 67dir/entry3.txt: stored 68entry4.txt: deflated 69entry5.txt: stored 70entry6.txt: deflated 71entry7.txt: deflated 72