Extract files from a .phar archive

There is something that I completely skipped for phar files. I am installing a project that requires phpunit, pdepend and other dependencies. I selected them as .phar files. But I can not extract files from them using the command line tool (php command). I was looking for a problem and I did not answer anything to this question. Can anyone help?

+47
php phar
Oct 21 '12 at 11:29
source share
7 answers

Yes, this library can do this: https://github.com/koto/phar-util

phar-extract library.phar output-directory

+22
Oct 21 '12 at 11:30
source share

Continuing to answer @pozss, you can actually use PharData-> extractTo in a simple single line line:

php -r '$phar = new Phar("phar-file.phar"); $phar->extractTo("./directory");' 
+79
Jan 20 '14 at 8:34
source share

Not sure if it is new, but according to PHP 5.4.16 this works:

 phar extract -f %some phar file% 

phar is retrieved relative to your current working directory.

+52
Mar 25 '14 at 3:51
source share

The phpStorm IDE can be used to view the contents of phar archives.

+10
Jul 25 '15 at 15:34
source share

This site easily converts .phar files to .zip files.

Try it.

+6
Jun 03 '14 at 6:08
source share

If you want to just use it, you should include it as phar:///path/to/myphar.phar/file.php .

But if you really want to unzip it, see the PharData class - of unknown (internal) extraction on the command line, but you can write a script for this.

+4
Oct 21 '12 at 11:32
source share

PHP also has functions for extracting phar archives, but files retain the current compression. To properly extract the archive, you must first convert it to an uncompressed format, and then extract it:

 <?php $phar = new Phar('Someclass.phar'); $phar2 = $phar->convertToExecutable (Phar::TAR,Phar::NONE); // Convert to an uncompressed tar archive $phar2->extractTo('/some/path/'); // Extract all files 

This will give you all the files without compression!

0
Jun 17 '15 at 12:37
source share



All Articles