ZipArchive::extractTo

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

ZipArchive::extractTo解压缩文件

说明

public ZipArchive::extractTo(string $pathto, array|string|null $files = null): bool

将完整存档或指定文件提取到指定的目录。

警告

提取的文件和目录的默认权限提供尽可能广泛的访问权限。这可以通过设置当前 umask 来限制,可以使用 umask() 更改。

参数

pathto

解压缩的本地目标路径

files

要提取的条目。接受单个条目名称或名称数组。

返回值

成功时返回 true, 或者在失败时返回 false

范例

示例 #1 提取所有条目

<?php
$zip
= new ZipArchive;
if (
$zip->open('test.zip') === TRUE) {
$zip->extractTo('/my/destination/dir/');
$zip->close();
echo
'ok';
} else {
echo
'failed';
}
?>

示例 #2 提取两个条目

<?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';
}
?>

注释

注意:

Windows NTFS file systems do not support some characters in filenames, namely <|>*?":. Filenames with a trailing dot are not supported either. Contrary to some extraction tools, this method does not replace these characters with an underscore, but instead fails to extract such files.

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top