ZipArchive::extractTo

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

ZipArchive::extractTo解压缩文件

说明

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

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

警告

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

出于安全原因,不会恢复原始权限。有关如何还原的示例,请参阅 ZipArchive::getExternalAttributesIndex() 页面上的代码示例

参数

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.

To Top