1--TEST-- 2setCompressionName and setCompressionIndex methods 3--SKIPIF-- 4<?php 5/* $Id$ */ 6if (!extension_loaded('zip')) die('skip'); 7?> 8--FILE-- 9<?php 10$tmpfile = dirname(__FILE__) . '/__tmp_oo_set_compression.zip'; 11 12if (file_exists($tmpfile)) { 13 unlink($tmpfile); 14} 15 16// generate the ZIP file 17$zip = new ZipArchive; 18if ($zip->open($tmpfile, ZipArchive::CREATE) !== TRUE) { 19 exit('failed'); 20} 21$txt = file_get_contents(__FILE__); 22$zip->addFromString('entry1.txt', $txt); 23$zip->addFromString('entry2.txt', $txt); 24$zip->addFromString('dir/entry3.txt', $txt); 25$zip->addFromString('entry4.txt', $txt); 26$zip->addFromString('entry5.txt', $txt); 27$zip->addFromString('entry6.txt', $txt); 28$zip->addFromString('entry7.txt', $txt); 29 30var_dump($zip->setCompressionName('entry2.txt', ZipArchive::CM_DEFAULT)); 31var_dump($zip->setCompressionName('dir/entry3.txt', ZipArchive::CM_STORE)); 32var_dump($zip->setCompressionName('entry4.txt', ZipArchive::CM_DEFLATE)); 33 34var_dump($zip->setCompressionIndex(4, ZipArchive::CM_STORE)); 35var_dump($zip->setCompressionIndex(5, ZipArchive::CM_DEFLATE)); 36var_dump($zip->setCompressionIndex(6, ZipArchive::CM_DEFAULT)); 37 38if (!$zip->close()) { 39 exit('failed'); 40} 41 42 43// check the ZIP file 44$zip = zip_open($tmpfile); 45if (!is_resource($zip)) { 46 exit('failed'); 47} 48 49while ($e = zip_read($zip)) { 50 echo zip_entry_name($e) . ': ' . zip_entry_compressionmethod($e) . "\n"; 51} 52zip_close($zip); 53?> 54--CLEAN-- 55<?php 56$tmpfile = dirname(__FILE__) . '/__tmp_oo_set_compression.zip'; 57unlink($tmpfile); 58?> 59--EXPECT-- 60bool(true) 61bool(true) 62bool(true) 63bool(true) 64bool(true) 65bool(true) 66entry1.txt: deflated 67entry2.txt: deflated 68dir/entry3.txt: stored 69entry4.txt: deflated 70entry5.txt: stored 71entry6.txt: deflated 72entry7.txt: deflated 73