PHP8 ZipArchive::setCompressionIndex

2024-02-27 11:09 更新

(PHP 7, PHP 8, PECL zip >= 1.13.0)

ZipArchive::setCompressionIndex — 設置由其索引定義的條目的壓縮方法

說明

public ZipArchive::setCompressionIndex(int $index, int $method, int $compflags = 0): bool

設置由條目索引定義的條目的壓縮方法。

參數 

index

條目的索引。

method

壓縮方法,ZipArchive::CM_* 常量之一。

compflags

壓縮級別。

返回值 

成功時返回 true, 或者在失敗時返回 false。

示例 

示例 #1 使用不同的壓縮方法將文件添加到存檔中

<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
    $zip->addFromString('foo', 'Some text');
    $zip->addFromString('bar', 'Some other text');
    $zip->setCompressionIndex(0, ZipArchive::CM_STORE);
    $zip->setCompressionIndex(1, ZipArchive::CM_DEFLATE);
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號