PHP8 ZipArchive::getFromName

2024-02-26 14:05 更新

(PHP 5 >= 5.2.0, PHP 7, PHP 8, PECL zip >= 1.1.0)

ZipArchive::getFromName — 使用其名稱返回條目內(nèi)容

說明

public ZipArchive::getFromName(string $name, int $len = 0, int $flags = 0): string|false

使用條目名稱返回條目內(nèi)容。

參數(shù) 

name

條目的名稱

len

要從條目中讀取的長度。如果 ,則 讀取整個條目。0

flags

用于查找條目的標志。以下值可能 被 ORed。

  • ZipArchive::FL_UNCHANGED

  • ZipArchive::FL_COMPRESSED

  • ZipArchive::FL_NOCASE

返回值 

返回 success 條目的內(nèi)容 或者在失敗時返回 false。

示例 

示例 #1 獲取文件內(nèi)容

<?php
$zip = new ZipArchive;
if ($zip->open('test1.zip') === TRUE) {
    echo $zip->getFromName('testfromfile.php');
    $zip->close();
} else {
    echo 'failed';
}
?>

示例 #2 從 zip 條目轉(zhuǎn)換圖像

<?php
$z = new ZipArchive();
if ($z->open(dirname(__FILE__) . '/test_im.zip')) {
    $im_string = $z->getFromName("pear_item.gif");
    $im = imagecreatefromstring($im_string);
    imagepng($im, 'b.png');
}
?>

參見 

  • ZipArchive::getFromIndex() - 使用其索引返回條目內(nèi)容


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號