Sami Sami - 4 months ago 55
PHP Question

PHP - file_get_contents() of a file inside a subdirectory in a zip file

I have a

.zip
file with multiple subdirectories and files inside them. How to use
file_get_contents()
to get the content of a file inside one of the subdirectories of the
zip
file?

Answer

If you've got the Zip extension installed, it should have registered the zip:// compression wrapper. Try the following:

$result = file_get_contents('zip://path_to_my.zip#subDir/foo.txt');