Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP read a text file from a directory of zip files

Tags:

file

php

zip

I have a directory which contains a set of zipped files. each of these files has foo.txt file in it.

How can I read this text file from each zip?

I know glob is used to list all files from the directory

like image 759
Alex Avatar asked Feb 25 '23 14:02

Alex


1 Answers

PHP has an extension that allows you to work with ZIP archives.

Note that to access that one file you don't need to unzip the whole archive. The ZipArchive::extractTo method allows you to specify what to extract.

$zip = new ZipArchive;
$res = $zip->open('test.zip');
$zip->extractTo('my/extract/folder/', 'foo.txt');
like image 122
Alin Purcaru Avatar answered Mar 06 '23 17:03

Alin Purcaru