如何将文件从Phar内部复制到外部


How can I copy a file from the inside of a Phar to the outside

我想知道是否可以将文件从Phar内部复制到外部。

以及在适当的情况下如何做到这一点。

复制函数将从同一Phar调用。

您可以使用Phar::extractTo来执行此操作。

文件说明如下:

Phar::extractTo--将Phar存档的内容提取到目录

示例用法:

public bool Phar::extractTo ( string $pathto [, string|array $files [, bool $overwrite = false ]] )

注意:您的php.ini文件必须将phar.readonly设置为0才能正常工作。

文档中的示例用法:

<?php
try {
    $phar = new Phar('myphar.phar');
    $phar->extractTo('/full/path'); // extract all files
    $phar->extractTo('/another/path', 'file.txt'); // extract only file.txt
    $phar->extractTo('/this/path',
        array('file1.txt', 'file2.txt')); // extract 2 files only
    $phar->extractTo('/third/path', null, true); // extract all files, and overwrite
} catch (Exception $e) {
    // handle errors
}
?>