[英]How can I copy a file from the inside of a Phar to the outside
I would like to know if is it possible to copy a file from inside of a Phar to outside of it.我想知道是否可以将文件从 Phar 内部复制到外部。
And how to do it if appropriate.以及如何在适当的情况下做到这一点。
The copy function will be called from this same Phar.复制函数将从同一个 Phar 调用。
You can use Phar::extractTo
to do this.您可以使用
Phar::extractTo
来执行此操作。
The documentation for this states the following:文档说明如下:
Phar::extractTo — Extract the contents of a phar archive to a directory
Phar::extractTo — 将 phar 存档的内容提取到目录
With the example usage:使用示例:
public bool Phar::extractTo ( string $pathto [, string|array $files [, bool $overwrite = false ]] )
Note: Your php.ini
file must have phar.readonly
to be set to 0
for this to work.注意:您的
php.ini
文件必须将phar.readonly
设置为0
才能工作。
An example usage from the docs:文档中的示例用法:
<?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
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.