简体   繁体   中英

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.

And how to do it if appropriate.

The copy function will be called from this same Phar.

You can use Phar::extractTo to do this.

The documentation for this states the following:

Phar::extractTo — Extract the contents of a phar archive to a directory

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.

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
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM