简体   繁体   中英

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

My test.gz contains for instance : image1.jpg.

How can I decompress the test.gz so it gives me 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

regards

You need to use PHP PharData to extract and read its content.

To extract tar or tar.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 />";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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