Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use tar.gz file like a folder?

Tags:

php

tar

Does PHP have an extension that permits to use a tar.gz like a folder?

I have some file that uses a similar structure and I don't need to extract all to read information about it, so can I make file_get_contents("my/path/to/tar/something.tar.gz/out.json");?

like image 580
Larandar Avatar asked Feb 09 '12 18:02

Larandar


People also ask

Can we tar a directory?

Tape Archive or tar is a file format for creating files and directories into an archive while preserving filesystem information such as permissions. We can use the tar command to create tar archives, extract the archives, view files and directories stored in the archives, and append files to an existing archive.


1 Answers

Use PHP's Phar extension. For an introduction, see PHP: Using Phar Archives: Introduction.

file_get_contents("phar://my/path/to/tar/something.tar.gz/out.json");

If you don't already have Phar, you can install the PHP_Archive package or use the PECL extension.

like image 160
kba Avatar answered Oct 15 '22 10:10

kba