简体   繁体   English

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

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

My test.gz contains for instance : image1.jpg.我的 test.gz 包含例如:image1.jpg。

How can I decompress the test.gz so it gives me image1.jpg ?如何解压缩 test.gz 以便它给我 image1.jpg ?

I tried that method:我试过这种方法:

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

but it supposes you need to know the filename contained in the .gz file但它假设您需要知道 .gz 文件中包含的文件名

regards问候

You need to use PHP PharData to extract and read its content.您需要使用 PHP PharData来提取和读取其内容。

To extract tar or tar.gz :提取tartar.gz

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

And to list all files, you can use :要列出所有文件,您可以使用:

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