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