本文整理汇总了PHP中ZipArchive::setCompressionIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP ZipArchive::setCompressionIndex方法的具体用法?PHP ZipArchive::setCompressionIndex怎么用?PHP ZipArchive::setCompressionIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipArchive
的用法示例。
在下文中一共展示了ZipArchive::setCompressionIndex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ZipArchive
// generate the ZIP file
$zip = new ZipArchive();
if ($zip->open($tmpfile, ZipArchive::CREATE) !== TRUE) {
exit('failed');
}
$txt = file_get_contents(__FILE__);
$zip->addFromString('entry1.txt', $txt);
$zip->addFromString('entry2.txt', $txt);
$zip->addFromString('dir/entry3.txt', $txt);
$zip->addFromString('entry4.txt', $txt);
$zip->addFromString('entry5.txt', $txt);
$zip->addFromString('entry6.txt', $txt);
$zip->addFromString('entry7.txt', $txt);
var_dump($zip->setCompressionName('entry2.txt', ZipArchive::CM_DEFAULT));
var_dump($zip->setCompressionName('dir/entry3.txt', ZipArchive::CM_STORE));
var_dump($zip->setCompressionName('entry4.txt', ZipArchive::CM_DEFLATE));
var_dump($zip->setCompressionIndex(4, ZipArchive::CM_STORE));
var_dump($zip->setCompressionIndex(5, ZipArchive::CM_DEFLATE));
var_dump($zip->setCompressionIndex(6, ZipArchive::CM_DEFAULT));
if (!$zip->close()) {
exit('failed');
}
// check the ZIP file
$zip = zip_open($tmpfile);
if (!is_resource($zip)) {
exit('failed');
}
while ($e = zip_read($zip)) {
echo zip_entry_name($e) . ': ' . zip_entry_compressionmethod($e) . "\n";
}
zip_close($zip);
示例2: dl
<?php
error_reporting(E_ALL);
if (!extension_loaded('zip')) {
dl('zip.so');
}
$zip = new ZipArchive();
$filename = "a.zip";
if (!$zip->open($filename, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) {
exit("cannot open <{$filename}>\n");
}
$zip->addFromString("testfilephp.txt", "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt", "#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile("too.php", "testfromfile.php");
$zip->setCompressionName("testfilephp2.txt", ZipArchive::CM_STORE);
$zip->setCompressionIndex(2, ZipArchive::CM_STORE);
$zip->close();
示例3: tempnam
<?php
$str = 'temp';
$dir = tempnam(sys_get_temp_dir(), __FILE__);
unlink($dir);
mkdir($dir);
$archive = new ZipArchive();
$archive->open("{$dir}/comptest.zip", ZipArchive::CREATE);
$archive->addFromString("A.txt", $str);
$archive->addFromString("B.txt", $str);
var_dump($archive->setCompressionIndex(0, ZIPArchive::CM_STORE));
var_dump($archive->setCompressionName("B.txt", ZIPArchive::CM_STORE));
$archive->close();
unlink("{$dir}/comptest.zip");
rmdir($dir);