Book/zip-Phpdoc专题
Zip
目录
- 简介
- 安装/配置
- 预定义常量
- 范例
- ZipArchive — ZipArchive 类
- ZipArchive::addEmptyDir — Add a new directory
- ZipArchive::addFile — Adds a file to a ZIP archive from the given path
- ZipArchive::addFromString — Add a file to a ZIP archive using its contents
- ZipArchive::addGlob — Add files from a directory by glob pattern
- ZipArchive::addPattern — Add files from a directory by PCRE pattern
- ZipArchive::close — Close the active archive (opened or newly created)
- ZipArchive::count — Counts the number of files in the archive
- ZipArchive::deleteIndex — Delete an entry in the archive using its index
- ZipArchive::deleteName — Delete an entry in the archive using its name
- ZipArchive::extractTo — 解压缩文件
- ZipArchive::getArchiveComment — Returns the Zip archive comment
- ZipArchive::getCommentIndex — Returns the comment of an entry using the entry index
- ZipArchive::getCommentName — Returns the comment of an entry using the entry name
- ZipArchive::getExternalAttributesIndex — Retrieve the external attributes of an entry defined by its index
- ZipArchive::getExternalAttributesName — Retrieve the external attributes of an entry defined by its name
- ZipArchive::getFromIndex — Returns the entry contents using its index
- ZipArchive::getFromName — Returns the entry contents using its name
- ZipArchive::getNameIndex — Returns the name of an entry using its index
- ZipArchive::getStatusString — Returns the status error message, system and/or zip messages
- ZipArchive::getStream — Get a file handler to the entry defined by its name (read only)
- ZipArchive::isCompressionMethodSupported — Check if a compression method is supported by libzip
- ZipArchive::isEncryptionMethodSupported — Check if a encryption method is supported by libzip
- ZipArchive::locateName — Returns the index of the entry in the archive
- ZipArchive::open — Open a ZIP file archive
- ZipArchive::registerCancelCallback — Register a callback to allow cancellation during archive close.
- ZipArchive::registerProgressCallback — Register a callback to provide updates during archive close.
- ZipArchive::renameIndex — Renames an entry defined by its index
- ZipArchive::renameName — Renames an entry defined by its name
- ZipArchive::replaceFile — Replace file in ZIP archive with a given path
- ZipArchive::setArchiveComment — Set the comment of a ZIP archive
- ZipArchive::setCommentIndex — Set the comment of an entry defined by its index
- ZipArchive::setCommentName — Set the comment of an entry defined by its name
- ZipArchive::setCompressionIndex — Set the compression method of an entry defined by its index
- ZipArchive::setCompressionName — Set the compression method of an entry defined by its name
- ZipArchive::setEncryptionIndex — Set the encryption method of an entry defined by its index
- ZipArchive::setEncryptionName — Set the encryption method of an entry defined by its name
- ZipArchive::setExternalAttributesIndex — Set the external attributes of an entry defined by its index
- ZipArchive::setExternalAttributesName — Set the external attributes of an entry defined by its name
- ZipArchive::setMtimeIndex — Set the modification time of an entry defined by its index
- ZipArchive::setMtimeName — Set the modification time of an entry defined by its name
- ZipArchive::setPassword — Set the password for the active archive
- ZipArchive::statIndex — Get the details of an entry defined by its index
- ZipArchive::statName — Get the details of an entry defined by its name
- ZipArchive::unchangeAll — Undo all changes done in the archive
- ZipArchive::unchangeArchive — Revert all global changes done in the archive
- ZipArchive::unchangeIndex — Revert all changes done to an entry at the given index
- ZipArchive::unchangeName — Revert all changes done to an entry with the given name
- Zip 函数
- zip_close — 关闭一个ZIP档案文件
- zip_entry_close — 关闭目录项
- zip_entry_compressedsize — 检索目录项压缩过后的大小
- zip_entry_compressionmethod — 检索目录实体的压缩方法
- zip_entry_filesize — 检索目录实体的实际大小
- zip_entry_name — 检索目录项的名称
- zip_entry_open — 打开用于读取的目录实体
- zip_entry_read — 读取一个打开了的压缩目录实体
- zip_open — 打开ZIP存档文件
- zip_read — 读取ZIP存档文件中下一项
简介
一个用 Zip 压缩的文件存档。
类摘要
ZipArchive
class ZipArchive {
/* 属性 */
/* 方法 */
public bool
addEmptyDir ( <span
class="methodparam">string $dirname
[, int
$flags = 0 ] )
public bool
addFile ( <span
class="methodparam">string $filename
[, string
$entryname = null [,
int $start<span
class="initializer"> = 0 [, <span
class="methodparam">int $length<span
class="initializer"> = 0 [, <span
class="methodparam">int $flags<span
class="initializer"> = ZipArchive::FL_OVERWRITE ]]]]
)
public bool
addFromString ( <span
class="methodparam">string $name ,
string
$contents [, <span
class="type">int $flags =
ZipArchive::FL_OVERWRITE ] )
public <span
class="type">arrayfalse <span
class="methodname">addGlob ( <span
class="type">string $pattern [, <span
class="methodparam">int $flags<span
class="initializer"> = 0 [, <span
class="methodparam">array $options<span
class="initializer"> = array() ]] )
public <span
class="type">arrayfalse <span
class="methodname">addPattern ( <span
class="type">string $pattern [, <span
class="methodparam">string $path<span
class="initializer"> = "." [, <span
class="methodparam">array $options<span
class="initializer"> = array() ]] )
public bool close ( <span class="methodparam">void )
public int <span class="methodname">count ( void )
public bool
deleteIndex ( <span
class="methodparam">int $index )
public bool
deleteName ( <span
class="methodparam">string $name )
bool extractTo
( string
$destination [, <span
class="type">mixed $entries ] )
public <span
class="type">stringfalse <span
class="methodname">getArchiveComment ([ <span
class="methodparam">int $flags ] )
public <span
class="type">stringfalse <span
class="methodname">getCommentIndex ( <span
class="methodparam">int $index [,
int $flags
] )
public <span
class="type">stringfalse <span
class="methodname">getCommentName ( <span
class="methodparam">string $name [,
int $flags
] )
public bool
GetExternalAttributesIndex ( <span
class="methodparam">int $index ,
int &$opsys
, int
&$attr [, <span
class="type">int $flags ] )
public bool
getExternalAttributesName ( <span
class="methodparam">string $name ,
int &$opsys
, int
&$attr [, <span
class="type">int $flags ] )
public <span
class="type">stringfalse <span
class="methodname">getFromIndex ( <span
class="type">int $index [, <span
class="methodparam">int $length<span
class="initializer"> = 0 [, <span
class="methodparam">int $flags ]] )
public <span
class="type">stringfalse <span
class="methodname">getFromName ( <span
class="type">string $name [, <span
class="methodparam">int $length<span
class="initializer"> = 0 [, <span
class="methodparam">int $flags ]] )
public <span
class="type">stringfalse <span
class="methodname">getNameIndex ( <span
class="type">int $index [, <span
class="methodparam">int $flags ] )
public <span class="type">stringfalse <span class="methodname">getStatusString ( <span class="methodparam">void )
public <span
class="type">resourcefalse <span
class="methodname">getStream ( <span
class="type">string $name )
public bool
isCompressionMethodSupported ( <span
class="methodparam">int $method [,
bool $encode<span
class="initializer"> = true ] )
public bool
isEncryptionMethodSupported ( <span
class="methodparam">int $method [,
bool $encode<span
class="initializer"> = true ] )
public <span
class="type">intfalse <span
class="methodname">locateName ( <span
class="type">string $name [, <span
class="methodparam">int $flags ] )
public mixed
open ( <span
class="type">string $filename [, <span
class="methodparam">int $flags ] )
public bool
registerCancelCallback ( <span
class="methodparam">callable
$callback )
public bool
registerProgressCallback ( <span
class="methodparam">float $rate ,
callable
$callback )
public bool
renameIndex ( <span
class="methodparam">int $index ,
string
$newname )
public bool
renameName ( <span
class="methodparam">string $name ,
string
$newname )
public bool
replaceFile ( <span
class="methodparam">string $filename
, int
$index [, <span
class="type">int $start =
0 [, <span
class="type">int $length =
0 [, <span
class="type">int $flags =
0 ]]] )
public bool
setArchiveComment ( <span
class="methodparam">string $comment )
public bool
setCommentIndex ( <span
class="methodparam">int $index ,
string
$comment )
public bool
setCommentName ( <span
class="methodparam">string $name ,
string
$comment )
public bool
setCompressionIndex ( <span
class="methodparam">int $index ,
int
$comp_method [, <span
class="type">int $comp_flags =
0 ] )
public bool
setCompressionName ( <span
class="methodparam">string $name ,
int
$comp_method [, <span
class="type">int $comp_flags =
0 ] )
public bool
setEncryptionIndex ( <span
class="methodparam">int $index ,
int $method
[, string
$password ] )
public bool
setEncryptionName ( <span
class="methodparam">string $name ,
int $method
[, string
$password ] )
public bool
setExternalAttributesIndex ( <span
class="methodparam">int $index ,
int $opsys
, int $attr
[, int
$flags ] )
public bool
setExternalAttributesName ( <span
class="methodparam">string $name ,
int $opsys
, int $attr
[, int
$flags ] )
public bool
setMtimeIndex ( <span
class="methodparam">int $index ,
int
$timestamp [, <span
class="type">int $flags ] )
public bool
setMtimeName ( <span
class="methodparam">string $name ,
int
$timestamp [, <span
class="type">int $flags ] )
public bool
setPassword ( <span
class="methodparam">string $password
)
public <span
class="type">arrayfalse <span
class="methodname">statIndex ( <span
class="type">int $index [, <span
class="methodparam">int $flags ] )
public <span
class="type">arrayfalse <span
class="methodname">statName ( <span
class="type">string $name [, <span
class="methodparam">int $flags ] )
public bool unchangeAll ( <span class="methodparam">void )
public bool unchangeArchive ( <span class="methodparam">void )
public bool
unchangeIndex ( <span
class="methodparam">int $index )
public bool
unchangeName ( <span
class="methodparam">string $name )
}
属性
status
Zip Archive 的状态
statusSys
Zip Archive 的系统状态
numFiles
压缩包里的文件数
filename
在文件系统里的文件名
comment
压缩包的注释
ZipArchive::addEmptyDir
Add a new directory
说明
public bool
ZipArchive::addEmptyDir ( <span
class="methodparam">string $dirname
[, int
$flags = 0 ] )
Adds an empty directory in the archive.
参数
dirname
The directory to add.
flags
Bitmask consisting of ZipArchive::FL_ENC_GUESS,
ZipArchive::FL_ENC_UTF_8, ZipArchive::FL_ENC_CP437. The
behaviour of these constants is described on the
ZIP constants page.
返回值
成功时返回 true, 或者在失败时返回 false。
更新日志
| 版本 | 说明 |
|---|---|
| 8.0.0 / 1.18.0 | flags was added. |
范例
示例 #1 Create a new directory in an archive
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
if($zip->addEmptyDir('newDirectory')) {
echo 'Created a new root directory';
} else {
echo 'Could not create the directory';
}
$zip->close();
} else {
echo 'failed';
}
?>
ZipArchive::addFile
Adds a file to a ZIP archive from the given path
说明
public bool
ZipArchive::addFile ( <span
class="methodparam">string $filename
[, string
$entryname = null [,
int $start<span
class="initializer"> = 0 [, <span
class="methodparam">int $length<span
class="initializer"> = 0 [, <span
class="methodparam">int $flags<span
class="initializer"> = ZipArchive::FL_OVERWRITE ]]]]
)
Adds a file to a ZIP archive from a given path.
Note: 为了最大限度地提高代码可移植性,建议在 ZIP 文件名中使用斜线 (/) 做为目录分隔符。
参数
filename
The path to the file to add.
entryname
If supplied, this is the local name inside the ZIP archive that will
override the filename.
start
For partial copy, start position.
length
For partial copy, length to be copied, if 0 or -1 the whole file
(starting from start) is used.
flags
Bitmask consisting of ZipArchive::FL_OVERWRITE,
ZipArchive::FL_ENC_GUESS, ZipArchive::FL_ENC_UTF_8,
ZipArchive::FL_ENC_CP437. The behaviour of these constants is
described on the
ZIP constants page.
返回值
成功时返回 true, 或者在失败时返回 false。
更新日志
| 版本 | 说明 |
|---|---|
| 8.0.0 / 1.18.0 | flags was added. |
范例
This example opens a ZIP file archive test.zip and add the file
/path/to/index.txt. as newname.txt.
示例 #1 Open and add
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
$zip->addFile('/path/to/index.txt', 'newname.txt');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
注释
Note:
When a file is set to be added to the archive, PHP will lock the file. The lock is only released once the <span class="classname">ZipArchive object has been closed, either via ZipArchive::close or the <span class="classname">ZipArchive object being destroyed. This may prevent you from being able to delete the file being added until after the lock has been released.
参见
- ZipArchive::replaceFile
ZipArchive::addFromString
Add a file to a ZIP archive using its contents
说明
public bool
ZipArchive::addFromString ( <span
class="methodparam">string $name ,
string
$contents [, <span
class="type">int $flags =
ZipArchive::FL_OVERWRITE ] )
Add a file to a ZIP archive using its contents.
Note: 为了最大限度地提高代码可移植性,建议在 ZIP 文件名中使用斜线 (/) 做为目录分隔符。
参数
name
The name of the entry to create.
contents
The contents to use to create the entry. It is used in a binary safe
mode.
flags
Bitmask consisting of ZipArchive::FL_OVERWRITE,
ZipArchive::FL_ENC_GUESS, ZipArchive::FL_ENC_UTF_8,
ZipArchive::FL_ENC_CP437. The behaviour of these constants is
described on the
ZIP constants page.
返回值
成功时返回 true, 或者在失败时返回 false。
更新日志
| 版本 | 说明 |
|---|---|
| 8.0.0 / 1.18.0 | flags was added. |
范例
示例 #1 Add an entry to a new archive
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFromString('test.txt', 'file content goes here');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
示例 #2 Add file to a directory inside an archive
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
$zip->addFromString('dir/test.txt', 'file content goes here');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
ZipArchive::addGlob
Add files from a directory by glob pattern
说明
public <span
class="type">arrayfalse <span
class="methodname">ZipArchive::addGlob ( <span
class="methodparam">string $pattern
[, int
$flags = 0 [, <span
class="methodparam">array $options<span
class="initializer"> = array() ]] )
Add files from a directory which match the glob pattern.
Note: 为了最大限度地提高代码可移植性,建议在 ZIP 文件名中使用斜线 (/) 做为目录分隔符。
参数
pattern
A glob pattern against which files will be
matched.
flags
A bit mask of glob() flags.
options
An associative array of options. Available options are:
-
"add_path"
Prefix to prepend when translating to the local path of the file within the archive. This is applied after any remove operations defined by the "remove_path" or "remove_all_path" options.
-
"remove_path"
Prefix to remove from matching file paths before adding to the archive.
-
"remove_all_path"
trueto use the file name only and add to the root of the archive. -
"flags"
Bitmask consisting of
ZipArchive::FL_OVERWRITE,ZipArchive::FL_ENC_GUESS,ZipArchive::FL_ENC_UTF_8,ZipArchive::FL_ENC_CP437. The behaviour of these constants is described on the ZIP constants page. -
"comp_method"
Compression method, one of the *`ZipArchive::CM_`** constants, see ZIP constants page.
-
"comp_flags"
Compression level.
-
"enc_method"
Encryption method, one of the *`ZipArchive::EM_`** constants, see ZIP constants page.
-
"enc_password"
Password used for encryption.
返回值
An array of added files on success
或者在失败时返回 false
更新日志
| 版本 | 说明 |
|---|---|
| 8.0.0 / 1.18.0 | "flags" in options was added. |
| 8.0.0 / 1.18.1 | "comp_method", "comp_flags", "enc_method" and "enc_password" in options were added. |
范例
示例 #1 ZipArchive::addGlob example
Add all php scripts and text files from current working directory
<?php
$zip = new ZipArchive();
$ret = $zip->open('application.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
if ($ret !== TRUE) {
printf('Failed with code %d', $ret);
} else {
$options = array('add_path' => 'sources/', 'remove_all_path' => TRUE);
$zip->addGlob('*.{php,txt}', GLOB_BRACE, $options);
$zip->close();
}
?>
参见
- ZipArchive::addFile
- ZipArchive::addPattern
ZipArchive::addPattern
Add files from a directory by PCRE pattern
说明
public <span
class="type">arrayfalse <span
class="methodname">ZipArchive::addPattern ( <span
class="methodparam">string $pattern
[, string
$path = "." [, <span
class="methodparam">array $options<span
class="initializer"> = array() ]] )
Add files from a directory which match the regular expression pattern.
The operation is not recursive. The pattern will be matched against the
file name only.
参数
pattern
A PCRE pattern against which
files will be matched.
path
The directory that will be scanned. Defaults to the current working
directory.
options
An associative array of options accepted by <span
class="methodname">ZipArchive::addGlob.
返回值
An array of added files on success
或者在失败时返回 false
范例
示例 #1 ZipArchive::addPattern example
Add all php scripts and text files from current directory
<?php
$zip = new ZipArchive();
$ret = $zip->open('application.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
if ($ret !== TRUE) {
printf('Failed with code %d', $ret);
} else {
$directory = realpath('.');
$options = array('add_path' => 'sources/', 'remove_path' => $directory);
$zip->addPattern('/\.(?:php|txt)$/', $directory, $options);
$zip->close();
}
?>
参见
- ZipArchive::addFile
- ZipArchive::addGlob
ZipArchive::close
Close the active archive (opened or newly created)
说明
public bool ZipArchive::close ( <span class="methodparam">void )
Close opened or created archive and save changes. This method is automatically called at the end of the script.
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
ZipArchive::count
Counts the number of files in the archive
说明
public int <span class="methodname">ZipArchive::count ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Returns the number of files in the archive.
ZipArchive::deleteIndex
Delete an entry in the archive using its index
说明
public bool
ZipArchive::deleteIndex ( <span
class="methodparam">int $index )
Delete an entry in the archive using its index.
参数
index
Index of the entry to delete.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Delete file from archive using its index
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
$zip->deleteIndex(2);
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
ZipArchive::deleteName
Delete an entry in the archive using its name
说明
public bool
ZipArchive::deleteName ( <span
class="methodparam">string $name )
Delete an entry in the archive using its name.
参数
name
Name of the entry to delete.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Deleting a file and directory from an archive, using names
<?php
$zip = new ZipArchive;
if ($zip->open('test1.zip') === TRUE) {
$zip->deleteName('testfromfile.php');
$zip->deleteName('testDir/');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
ZipArchive::extractTo
解压缩文件
说明
bool <span
class="methodname">ZipArchive::extractTo ( <span
class="methodparam">string
$destination [, <span
class="type">mixed $entries ] )
将压缩文件解压缩到指定的目录
参数
destination
解压缩的本地目标路径
entries
解压缩的文件。它接受一个单独的文件名或一个文件名数组。
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Extract all entries
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
$zip->extractTo('/my/destination/dir/');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
示例 #2 Extract two entries
<?php
$zip = new ZipArchive;
$res = $zip->open('test_im.zip');
if ($res === TRUE) {
$zip->extractTo('/my/destination/dir/', array('pear_item.gif', 'testfromfile.php'));
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
ZipArchive::getArchiveComment
Returns the Zip archive comment
说明
public <span
class="type">stringfalse <span
class="methodname">ZipArchive::getArchiveComment ([ <span
class="methodparam">int $flags ] )
Returns the Zip archive comment.
参数
flags
If flags is set to ZipArchive::FL_UNCHANGED, the original
unchanged comment is returned.
返回值
Returns the Zip archive comment 或者在失败时返回 false.
范例
示例 #1 Dump an archive comment
<?php
$zip = new ZipArchive;
$res = $zip->open('test_with_comment.zip');
if ($res === TRUE) {
var_dump($zip->getArchiveComment());
/* Or using the archive property */
var_dump($zip->comment);
} else {
echo 'failed, code:' . $res;
}
?>
ZipArchive::getCommentIndex
Returns the comment of an entry using the entry index
说明
public <span
class="type">stringfalse <span
class="methodname">ZipArchive::getCommentIndex ( <span
class="methodparam">int $index [,
int $flags
] )
Returns the comment of an entry using the entry index.
参数
index
Index of the entry
flags
If flags is set to ZipArchive::FL_UNCHANGED, the original
unchanged comment is returned.
返回值
Returns the comment on success 或者在失败时返回 false.
范例
示例 #1 Dump an entry comment
<?php
$zip = new ZipArchive;
$res = $zip->open('test1.zip');
if ($res === TRUE) {
var_dump($zip->getCommentIndex(1));
} else {
echo 'failed, code:' . $res;
}
?>
ZipArchive::getCommentName
Returns the comment of an entry using the entry name
说明
public <span
class="type">stringfalse <span
class="methodname">ZipArchive::getCommentName ( <span
class="methodparam">string $name [,
int $flags
] )
Returns the comment of an entry using the entry name.
参数
name
Name of the entry
flags
If flags is set to ZipArchive::FL_UNCHANGED, the original
unchanged comment is returned.
返回值
Returns the comment on success 或者在失败时返回 false.
范例
示例 #1 Dump an entry comment
<?php
$zip = new ZipArchive;
$res = $zip->open('test1.zip');
if ($res === TRUE) {
var_dump($zip->getCommentName('test/entry1.txt'));
} else {
echo 'failed, code:' . $res;
}
?>
ZipArchive::getExternalAttributesIndex
Retrieve the external attributes of an entry defined by its index
说明
public bool
ZipArchive::GetExternalAttributesIndex (
int $index
, int
&$opsys , <span
class="type">int &$attr [, <span
class="methodparam">int $flags ] )
Retrieve the external attributes of an entry defined by its index.
参数
index
Index of the entry.
opsys
On success, receive the operating system code defined by one of the
ZipArchive::OPSYS_ constants.
attr
On success, receive the external attributes. Value depends on operating
system.
flags
If flags is set to ZipArchive::FL_UNCHANGED, the original
unchanged attributes are returned.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
This example extract all the entries of a ZIP archive test.zip and set
the Unix rights from external attributes.
示例 #1 Extract all entries with Unix rights
<?php
$zip = new ZipArchive();
if ($zip->open('test.zip') === TRUE) {
for ($idx=0 ; $s = $zip->statIndex($idx) ; $idx++) {
if ($zip->extractTo('.', $s['name'])) {
if ($zip->getExternalAttributesIndex($idx, $opsys, $attr)
&& $opsys==ZipArchive::OPSYS_UNIX) {
chmod($s['name'], ($attr >> 16) & 0777);
}
}
}
$zip->close();
echo "Ok\n";
} else {
echo "KO\n";
}
?>
ZipArchive::getExternalAttributesName
Retrieve the external attributes of an entry defined by its name
说明
public bool
ZipArchive::getExternalAttributesName (
string
$name , int
&$opsys , <span
class="type">int &$attr [, <span
class="methodparam">int $flags ] )
Retrieve the external attributes of an entry defined by its name.
参数
name
Name of the entry.
opsys
On success, receive the operating system code defined by one of the
ZipArchive::OPSYS_ constants.
attr
On success, receive the external attributes. Value depends on operating
system.
flags
If flags is set to ZipArchive::FL_UNCHANGED, the original
unchanged attributes are returned.
返回值
成功时返回 true, 或者在失败时返回 false。
ZipArchive::getFromIndex
Returns the entry contents using its index
说明
public <span
class="type">stringfalse <span
class="methodname">ZipArchive::getFromIndex ( <span
class="methodparam">int $index [,
int $length<span
class="initializer"> = 0 [, <span
class="methodparam">int $flags ]] )
Returns the entry contents using its index.
参数
index
Index of the entry
length
The length to be read from the entry. If 0, then the entire entry is
read.
flags
The flags to use to open the archive. the following values may be ORed
to it.
-
ZipArchive::FL_UNCHANGED -
ZipArchive::FL_COMPRESSED
返回值
Returns the contents of the entry on success 或者在失败时返回
false.
范例
示例 #1 Get the file contents
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
echo $zip->getFromIndex(2);
$zip->close();
} else {
echo 'failed';
}
?>
参见
- ZipArchive::getFromName
ZipArchive::getFromName
Returns the entry contents using its name
说明
public <span
class="type">stringfalse <span
class="methodname">ZipArchive::getFromName ( <span
class="methodparam">string $name [,
int $length<span
class="initializer"> = 0 [, <span
class="methodparam">int $flags ]] )
Returns the entry contents using its name.
参数
name
Name of the entry
length
The length to be read from the entry. If 0, then the entire entry is
read.
flags
The flags to use to find the entry. The following values may be ORed.
-
ZipArchive::FL_UNCHANGED -
ZipArchive::FL_COMPRESSED -
ZipArchive::FL_NOCASE
返回值
Returns the contents of the entry on success 或者在失败时返回
false.
范例
示例 #1 Get the file contents
<?php
$zip = new ZipArchive;
if ($zip->open('test1.zip') === TRUE) {
echo $zip->getFromName('testfromfile.php');
$zip->close();
} else {
echo 'failed';
}
?>
示例 #2 Convert an image from a zip entry
<?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
ZipArchive::getNameIndex
Returns the name of an entry using its index
说明
public <span
class="type">stringfalse <span
class="methodname">ZipArchive::getNameIndex ( <span
class="methodparam">int $index [,
int $flags
] )
Returns the name of an entry using its index.
参数
index
Index of the entry.
flags
If flags is set to ZipArchive::FL_UNCHANGED, the original
unchanged name is returned.
返回值
Returns the name on success 或者在失败时返回 false.
范例
示例 #1 ZipArchive::getNameIndex example
<?php
if ($zip->open('test.zip') == TRUE) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
// ...
}
}
?>
ZipArchive::getStatusString
Returns the status error message, system and/or zip messages
说明
public <span class="type">stringfalse <span class="methodname">ZipArchive::getStatusString ( <span class="methodparam">void )
Returns the status error message, system and/or zip messages.
参数
此函数没有参数。
返回值
Returns a string with the status message on
success 或者在失败时返回 false.
更新日志
| 版本 | 说明 |
|---|---|
| 8.0.0 / 1.18.0 | This method can be called on closed archive. |
ZipArchive::getStream
Get a file handler to the entry defined by its name (read only)
说明
public <span
class="type">resourcefalse <span
class="methodname">ZipArchive::getStream ( <span
class="methodparam">string $name )
Get a file handler to the entry defined by its name. For now it only supports read operations.
参数
name
The name of the entry to use.
返回值
Returns a file pointer (resource) on success 或者在失败时返回
false.
范例
示例 #1 Get the entry contents with <span class="function">fread and store it
<?php
$contents = '';
$z = new ZipArchive();
if ($z->open('test.zip')) {
$fp = $z->getStream('test');
if(!$fp) exit("failed\n");
while (!feof($fp)) {
$contents .= fread($fp, 2);
}
fclose($fp);
file_put_contents('t',$contents);
echo "done.\n";
}
?>
示例 #2 Same as the previous example but with <span class="function">fopen and the zip stream wrapper
<?php
$contents = '';
$fp = fopen('zip://' . dirname(__FILE__) . '/test.zip#test', 'r');
if (!$fp) {
exit("cannot open\n");
}
while (!feof($fp)) {
$contents .= fread($fp, 2);
}
echo "$contents\n";
fclose($fp);
echo "done.\n";
?>
示例 #3 Stream wrapper and image, can be used with the xml function as well
<?php
$im = imagecreatefromgif('zip://' . dirname(__FILE__) . '/test_im.zip#pear_item.gif');
imagepng($im, 'a.png');
?>
ZipArchive::isCompressionMethodSupported
Check if a compression method is supported by libzip
说明
public bool
ZipArchive::isCompressionMethodSupported
( int
$method [, <span
class="type">bool $encode =
true ] )
Check if a compression method is supported by libzip.
参数
method
The compression method, one of the *`ZipArchive::CM_`** constants.
encode
If true check for compression, else check for decompression.
返回值
成功时返回 true, 或者在失败时返回 false。
注释
Note:
This function is only available if built against libzip ≥ 1.7.0.
参见
- ZipArchive::setCompressionIndex
- ZipArchive::setCompressionName
ZipArchive::isEncryptionMethodSupported
Check if a encryption method is supported by libzip
说明
public bool
ZipArchive::isEncryptionMethodSupported
( int
$method [, <span
class="type">bool $encode =
true ] )
Check if a compression method is supported by libzip.
参数
method
The encryption method, one of the *`ZipArchive::EM_`** constants.
encode
If true check for encryption, else check for decryption.
返回值
成功时返回 true, 或者在失败时返回 false。
注释
Note:
This function is only available if built against libzip ≥ 1.7.0.
参见
- ZipArchive::setEncryptionIndex
- ZipArchive::setEncryptionName
ZipArchive::locateName
Returns the index of the entry in the archive
说明
public <span
class="type">intfalse <span
class="methodname">ZipArchive::locateName ( <span
class="methodparam">string $name [,
int $flags
] )
Locates an entry using its name.
参数
name
The name of the entry to look up
flags
The flags are specified by ORing the following values, or 0 for none of
them.
-
ZipArchive::FL_NOCASE -
ZipArchive::FL_NODIR
返回值
Returns the index of the entry on success 或者在失败时返回 false.
范例
示例 #1 Create an archive and then use it with <span class="function">ZipArchive::locateName
<?php
$file = 'testlocate.zip';
$zip = new ZipArchive;
if ($zip->open($file, ZipArchive::CREATE) !== TRUE) {
exit('failed');
}
$zip->addFromString('entry1.txt', 'entry #1');
$zip->addFromString('entry2.txt', 'entry #2');
$zip->addFromString('dir/entry2d.txt', 'entry #2');
if ($zip->status !== ZipArchive::ER_OK) {
echo "failed to write zip\n";
}
$zip->close();
if ($zip->open($file) !== TRUE) {
exit('failed');
}
echo $zip->locateName('entry1.txt') . "\n";
echo $zip->locateName('eNtry2.txt') . "\n";
echo $zip->locateName('eNtry2.txt', ZipArchive::FL_NOCASE) . "\n";
echo $zip->locateName('enTRy2d.txt', ZipArchive::FL_NOCASE|ZipArchive::FL_NODIR) . "\n";
$zip->close();
?>
以上例程会输出:
0
1
2
ZipArchive::open
Open a ZIP file archive
说明
public mixed
ZipArchive::open ( <span
class="methodparam">string $filename
[, int
$flags ] )
Opens a new or existing zip archive for reading, writing or modifying.
Since libzip 1.6.0, a empty file is not a valid archive any longer.
参数
filename
The file name of the ZIP archive to open.
flags
The mode to use to open the archive.
-
ZipArchive::OVERWRITE -
ZipArchive::CREATE -
ZipArchive::RDONLY -
ZipArchive::EXCL -
ZipArchive::CHECKCONS
返回值
Error codes
Returns true on success or the error code.
-
ZipArchive::ER_EXISTSFile already exists.
-
ZipArchive::ER_INCONSZip archive inconsistent.
-
ZipArchive::ER_INVALInvalid argument.
-
ZipArchive::ER_MEMORYMalloc failure.
-
ZipArchive::ER_NOENTNo such file.
-
ZipArchive::ER_NOZIPNot a zip archive.
-
ZipArchive::ER_OPENCan't open file.
-
ZipArchive::ER_READRead error.
-
ZipArchive::ER_SEEKSeek error.
范例
示例 #1 Open and extract
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
echo 'ok';
$zip->extractTo('test');
$zip->close();
} else {
echo 'failed, code:' . $res;
}
?>
示例 #2 Create an archive
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFromString('test.txt', 'file content goes here');
$zip->addFile('data.txt', 'entryname.txt');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
示例 #3 Create an temporary archive
<?php
$name = tempnam(sys_get_temp_dir(), "FOO");
$zip = new ZipArchive;
$res = $zip->open($name, ZipArchive::OVERWRITE); /* truncate as empty file is not valid */
if ($res === TRUE) {
$zip->addFile('data.txt', 'entryname.txt');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
ZipArchive::registerCancelCallback
Register a callback to allow cancellation during archive close.
说明
public bool
ZipArchive::registerCancelCallback (
callable
$callback )
Register a callback function to allow cancellation during archive
close.
参数
callback
If this function return 0 operation will continue, other value it will
be cancelled.
返回值
成功时返回 true, 或者在失败时返回 false。
注释
Note:
This function is only available if built against libzip ≥ 1.6.0.
范例
This example creates a ZIP file archive php.zip and cancel operation
on some run condition.
示例 #1 Archive a file
<?php
$zip = new ZipArchive();
if ($zip->open('php.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
$zip->addFile(PHP_BINARY, 'php');
$zip->registerCancelCallback(function () {
return ($someruncondition ? -1 : 0);
});
$zip->close();
}
参见
- ZipArchive::registerProgressCallback
ZipArchive::registerProgressCallback
Register a callback to provide updates during archive close.
说明
public bool
ZipArchive::registerProgressCallback (
float $rate
, callable
$callback )
Register a callback function to provide updates during archive close.
参数
rate
Change between each call of the callback (from 0.0 to 1.0).
callback
This function will receive the current state as a <span
class="type">float (from 0.0 to 1.0).
返回值
成功时返回 true, 或者在失败时返回 false。
注释
Note:
This function is only available if built against libzip ≥ 1.3.0.
范例
This example creates a ZIP file archive php.zip and show progression.
示例 #1 Archive a file
$zip = new ZipArchive();
if ($zip->open('php.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
$zip->addFile(PHP_BINARY, 'php');
$zip->registerProgressCallback(0.05, function ($r) {
printf("%d%%\n", $r * 100);
});
$zip->close();
}
参见
- ZipArchive::registerCancelCallback
ZipArchive::renameIndex
Renames an entry defined by its index
说明
public bool
ZipArchive::renameIndex ( <span
class="methodparam">int $index ,
string
$newname )
Renames an entry defined by its index.
参数
index
Index of the entry to rename.
newname
New name.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Rename one entry
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
$zip->renameIndex(2,'newname.txt');
$zip->close();
} else {
echo 'failed, code:' . $res;
}
?>
ZipArchive::renameName
Renames an entry defined by its name
说明
public bool
ZipArchive::renameName ( <span
class="methodparam">string $name ,
string
$newname )
Renames an entry defined by its name.
参数
name
Name of the entry to rename.
newname
New name.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Rename one entry
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
$zip->renameName('currentname.txt','newname.txt');
$zip->close();
} else {
echo 'failed, code:' . $res;
}
?>
ZipArchive::replaceFile
Replace file in ZIP archive with a given path
说明
public bool
ZipArchive::replaceFile ( <span
class="methodparam">string $filename
, int
$index [, <span
class="type">int $start =
0 [, <span
class="type">int $length =
0 [, <span
class="type">int $flags =
0 ]]] )
Replace file in ZIP archive with a given path.
Note: 为了最大限度地提高代码可移植性,建议在 ZIP 文件名中使用斜线 (/) 做为目录分隔符。
参数
filename
The path to the file to add.
index
The index of the file to be replaced, its name is unchanged.
start
For partial copy, start position.
length
For partial copy, length to be copied, if 0 or -1 the whole file
(starting from start) is used.
flags
Bitmask consisting of ZipArchive::FL_ENC_GUESS,
ZipArchive::FL_ENC_UTF_8, ZipArchive::FL_ENC_CP437. The
behaviour of these constants is described on the
ZIP constants page.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
This example opens a ZIP file archive test.zip and replaces index 1
entry with /path/to/index.txt.
示例 #1 Open and replace
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
$zip->replaceFile('/path/to/index.txt', 1);
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
参见
- ZipArchive::addFile
ZipArchive::setArchiveComment
Set the comment of a ZIP archive
说明
public bool
ZipArchive::setArchiveComment ( <span
class="methodparam">string $comment )
Set the comment of a ZIP archive.
参数
comment
The contents of the comment.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Create an archive and set a comment
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFromString('test.txt', 'file content goes here');
$zip->setArchiveComment('new archive comment');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
ZipArchive::setCommentIndex
Set the comment of an entry defined by its index
说明
public bool
ZipArchive::setCommentIndex ( <span
class="methodparam">int $index ,
string
$comment )
Set the comment of an entry defined by its index.
参数
index
Index of the entry.
comment
The contents of the comment.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Open an archive and set a comment for an entry
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
$zip->setCommentIndex(2, 'new entry comment');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
ZipArchive::setCommentName
Set the comment of an entry defined by its name
说明
public bool
ZipArchive::setCommentName ( <span
class="methodparam">string $name ,
string
$comment )
Set the comment of an entry defined by its name.
参数
name
Name of the entry.
comment
The contents of the comment.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Open an archive and set a comment for an entry
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
$zip->setCommentName('entry1.txt', 'new entry comment');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
ZipArchive::setCompressionIndex
Set the compression method of an entry defined by its index
说明
public bool
ZipArchive::setCompressionIndex ( <span
class="methodparam">int $index ,
int
$comp_method [, <span
class="type">int $comp_flags =
0 ] )
Set the compression method of an entry defined by its index.
参数
index
Index of the entry.
comp_method
The compression method, one of the *`ZipArchive::CM_`** constants.
comp_flags
Compression level.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Add files with different compression methods to an archive
<?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';
}
?>
ZipArchive::setCompressionName
Set the compression method of an entry defined by its name
说明
public bool
ZipArchive::setCompressionName ( <span
class="methodparam">string $name ,
int
$comp_method [, <span
class="type">int $comp_flags =
0 ] )
Set the compression method of an entry defined by its name.
参数
name
Name of the entry.
comp_method
The compression method, one of the *`ZipArchive::CM_`** constants.
comp_flags
Compression level.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Add files with different compression methods to an archive
<?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->setCompressionName('foo', ZipArchive::CM_STORE);
$zip->setCompressionName('bar', ZipArchive::CM_DEFLATE);
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
示例 #2 Add file and set compression method
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFile('foo.jpg', 'bar.jpg');
$zip->setCompressionName('bar.jpg', ZipArchive::CM_XZ);
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
ZipArchive::setEncryptionIndex
Set the encryption method of an entry defined by its index
说明
public bool
ZipArchive::setEncryptionIndex ( <span
class="methodparam">int $index ,
int $method
[, string
$password ] )
Set the encryption method of an entry defined by its index.
参数
index
Index of the entry.
method
The encryption method defined by one of the ZipArchive::EM_ constants.
password
Optional password, default used when missing.
返回值
成功时返回 true, 或者在失败时返回 false。
注释
Note:
This function is only available if built against libzip ≥ 1.2.0.
参见
- ZipArchive::setPassword
- ZipArchive::setEncryptionName
ZipArchive::setEncryptionName
Set the encryption method of an entry defined by its name
说明
public bool
ZipArchive::setEncryptionName ( <span
class="methodparam">string $name ,
int $method
[, string
$password ] )
Set the encryption method of an entry defined by its name.
参数
name
Name of the entry.
method
The encryption method defined by one of the ZipArchive::EM_ constants.
password
Optional password, default used when missing.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
This example creates a ZIP file archive test.zip and add the file
test.txt encrypted using the AES 256 method.
示例 #1 Archive and encrypt a file
<?php
$zip = new ZipArchive();
if ($zip->open('test.zip', ZipArchive::CREATE) === TRUE) {
$zip->setPassword('secret');
$zip->addFile('text.txt');
$zip->setEncryptionName('text.txt', ZipArchive::EM_AES_256);
$zip->close();
echo "Ok\n";
} else {
echo "KO\n";
}
?>
注释
Note:
This function is only available if built against libzip ≥ 1.2.0.
参见
- ZipArchive::setPassword
- ZipArchive::setEncryptionIndex
ZipArchive::setExternalAttributesIndex
Set the external attributes of an entry defined by its index
说明
public bool
ZipArchive::setExternalAttributesIndex (
int $index
, int
$opsys , <span
class="type">int $attr [, <span
class="methodparam">int $flags ] )
Set the external attributes of an entry defined by its index.
参数
index
Index of the entry.
opsys
The operating system code defined by one of the ZipArchive::OPSYS_
constants.
attr
The external attributes. Value depends on operating system.
flags
Optional flags. Currently unused.
返回值
成功时返回 true, 或者在失败时返回 false。
ZipArchive::setExternalAttributesName
Set the external attributes of an entry defined by its name
说明
public bool
ZipArchive::setExternalAttributesName (
string
$name , int
$opsys , <span
class="type">int $attr [, <span
class="methodparam">int $flags ] )
Set the external attributes of an entry defined by its name.
参数
name
Name of the entry.
opsys
The operating system code defined by one of the ZipArchive::OPSYS_
constants.
attr
The external attributes. Value depends on operating system.
flags
Optional flags. Currently unused.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
This example opens a ZIP file archive test.zip and add the file
test.txt with its Unix rights as external attributes.
示例 #1 Archive a file, with its Unix rights
<?php
$zip = new ZipArchive();
$stat = stat($filename='test.txt');
if (is_array($stat) && $zip->open('test.zip', ZipArchive::CREATE) === TRUE) {
$zip->addFile($filename);
$zip->setExternalAttributesName($filename, ZipArchive::OPSYS_UNIX, $stat['mode'] << 16);
$zip->close();
echo "Ok\n";
} else {
echo "KO\n";
}
?>
ZipArchive::setMtimeIndex
Set the modification time of an entry defined by its index
说明
public bool
ZipArchive::setMtimeIndex ( <span
class="methodparam">int $index ,
int
$timestamp [, <span
class="type">int $flags ] )
Set the modification time of an entry defined by its index.
参数
index
Index of the entry.
timestamp
The modification time (unix timestamp) of the file.
flags
Optional flags, unused for now.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
This example creates a ZIP file archive test.zip and add the file
test.txt with its modification date.
示例 #1 Archive a file
<?php
$zip = new ZipArchive();
if ($zip->open('test.zip', ZipArchive::CREATE) === TRUE) {
$zip->addFile('text.txt');
$zip->setMtimeIndex(0, mktime(0,0,0,12,25,2019));
$zip->close();
echo "Ok\n";
} else {
echo "KO\n";
}
?>
注释
Note:
This function is only available if built against libzip ≥ 1.0.0.
参见
- ZipArchive::setMtimeName
ZipArchive::setMtimeName
Set the modification time of an entry defined by its name
说明
public bool
ZipArchive::setMtimeName ( <span
class="methodparam">string $name ,
int
$timestamp [, <span
class="type">int $flags ] )
Set the modification time of an entry defined by its name.
参数
name
Name of the entry.
timestamp
The modification time (unix timestamp) of the file.
flags
Optional flags, unused for now.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
This example creates a ZIP file archive test.zip and add the file
test.txt with its modification date.
示例 #1 Archive a file
<?php
$zip = new ZipArchive();
if ($zip->open('test.zip', ZipArchive::CREATE) === TRUE) {
$zip->addFile('text.txt');
$zip->setMtimeName('text.txt', mktime(0,0,0,12,25,2019));
$zip->close();
echo "Ok\n";
} else {
echo "KO\n";
}
?>
注释
Note:
This function is only available if built against libzip ≥ 1.0.0.
参见
- ZipArchive::setMtimeIndex
ZipArchive::setPassword
Set the password for the active archive
说明
public bool
ZipArchive::setPassword ( <span
class="methodparam">string $password
)
Sets the password for the active archive.
参数
password
The password to be used for the archive.
返回值
成功时返回 true, 或者在失败时返回 false。
注释
Note:
As of PHP 7.2.0 and libzip 1.2.0 the password is used to decompress the archive, and is also the default password for <span class="methodname">ZipArchive::setEncryptionName and <span class="methodname">ZipArchive::setEncryptionIndex. Formerly, this function only set the password to be used to decompress the archive; it did not turn a non-password-protected <span class="classname">ZipArchive into a password-protected <span class="classname">ZipArchive.
参见
- ZipArchive::setEncryptionIndex
- ZipArchive::setEncryptionName
ZipArchive::statIndex
Get the details of an entry defined by its index
说明
public <span
class="type">arrayfalse <span
class="methodname">ZipArchive::statIndex ( <span
class="methodparam">int $index [,
int $flags
] )
The function obtains information about the entry defined by its index.
参数
index
Index of the entry
flags
ZipArchive::FL_UNCHANGED may be ORed to it to request information
about the original file in the archive, ignoring any changes made.
返回值
Returns an array containing the entry details 或者在失败时返回
false.
范例
示例 #1 Dump the stat info of an entry
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
print_r($zip->statIndex(3));
$zip->close();
} else {
echo 'failed, code:' . $res;
}
?>
以上例程的输出类似于:
Array
(
[name] => foobar/baz
[index] => 3
[crc] => 499465816
[size] => 27
[mtime] => 1123164748
[comp_size] => 24
[comp_method] => 8
)
ZipArchive::statName
Get the details of an entry defined by its name
说明
public <span
class="type">arrayfalse <span
class="methodname">ZipArchive::statName ( <span
class="methodparam">string $name [,
int $flags
] )
The function obtains information about the entry defined by its name.
参数
name
Name of the entry
flags
The flags argument specifies how the name lookup should be done. Also,
ZipArchive::FL_UNCHANGED may be ORed to it to request information
about the original file in the archive, ignoring any changes made.
-
ZipArchive::FL_NOCASE -
ZipArchive::FL_NODIR -
ZipArchive::FL_UNCHANGED
返回值
Returns an array containing the entry details 或者在失败时返回
false.
范例
示例 #1 Dump the stat info of an entry
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
print_r($zip->statName('foobar/baz'));
$zip->close();
} else {
echo 'failed, code:' . $res;
}
?>
以上例程的输出类似于:
Array
(
[name] => foobar/baz
[index] => 3
[crc] => 499465816
[size] => 27
[mtime] => 1123164748
[comp_size] => 24
[comp_method] => 8
)
ZipArchive::unchangeAll
Undo all changes done in the archive
说明
public bool ZipArchive::unchangeAll ( <span class="methodparam">void )
Undo all changes done in the archive.
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
ZipArchive::unchangeArchive
Revert all global changes done in the archive
说明
public bool ZipArchive::unchangeArchive ( <span class="methodparam">void )
Revert all global changes to the archive. For now, this only reverts archive comment changes.
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
ZipArchive::unchangeIndex
Revert all changes done to an entry at the given index
说明
public bool
ZipArchive::unchangeIndex ( <span
class="methodparam">int $index )
Revert all changes done to an entry at the given index.
参数
index
Index of the entry.
返回值
成功时返回 true, 或者在失败时返回 false。
ZipArchive::unchangeName
Revert all changes done to an entry with the given name
说明
public bool
ZipArchive::unchangeName ( <span
class="methodparam">string $name )
Revert all changes done to an entry.
参数
name
Name of the entry.
返回值
成功时返回 true, 或者在失败时返回 false。