繁体   English   中英

PHP:如何检索 .gz 中包含的文件的文件名?

[英]PHP: how to retrieve the filename of the file contained in .gz?

我的 test.gz 包含例如:image1.jpg。

如何解压缩 test.gz 以便它给我 image1.jpg ?

我试过这种方法:

$file = gzopen($file_name, 'rb');
$out_file = fopen($out_file_name, 'wb');

但它假设您需要知道 .gz 文件中包含的文件名

问候

您需要使用 PHP PharData来提取和读取其内容。

提取tartar.gz

    $phar = new PharData('myphar.tar');
    $phar->extractTo('/full/path');

要列出所有文件,您可以使用:

archive = new PharData('/upload/directory/myphar.tar.gz');

foreach (new RecursiveIteratorIterator($archive) as $file) {
    echo $file . "<br />";
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM