Extracting files from .phar archive

怎甘沉沦 提交于 2019-12-02 16:58:42

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

phar-extract library.phar output-directory

Extending on @pozs’s answer, you can actually use PharData->extractTo in a simple one-liner:

php -r '$phar = new Phar("phar-file.phar"); $phar->extractTo("./directory");'

Not sure if it's new, but under PHP 5.4.16 this works:

phar extract -f %some phar file%

The phar is extracted relative to your current working directory.

PhpStorm IDE can be used for viewing content of phar archives.

naju

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

Try it out.

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

But if you really want to unpack it, see the PharData class - no known (internal) extraction in command line, but you can write a script for that.

PHP also has functions for extracting phar archives, but the files keep the current compression. To properly extract an archive it has to be converted into a uncompressed form first and then extracted:

<?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 uncompressed!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!