Zip support seems to be shaky, in that just attempting to open a Zip file (created by 7-Zip) with both the 'zlib' and 'zip' extensions enabled renders the following error:
Error: Cannot convert phar archive "C:/Development/webdir/public_html/TestPhar.zip", unable to open entry "TestPhar/" contents: phar error: internal corruption of zip-based phar "C:/Development/webdir/public_html/TestPhar.zip" (local header of file "TestPhar/" does not match central directory)
Stick to GZ's and BZ2's (but don't forget to enable the BZ2 extension if necessary).
Phar can ONLY open executable Phar's and PharData can ONLY open non-executable Phar's. Both have the ability to convert between the two formats.
However, you can reference a file within a Phar regardless of whether it's executable using the Phar stream wrapper (file_get_contents('phar://<Phar file>/subdirectory/subdirectory/somefile.txt')).
Dustin OpreaPhar::__construct
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Phar::__construct
Референца за `phar.construct.php` со подобрена типографија и навигација.
Phar::__construct
(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL phar >= 1.0.0)
Phar::__construct — Конструирај објект Phar архивa
= NULL
Параметри
filename-
Патека до постоечка Phar архива или архива што треба да се креира. Наставката на името на датотеката мора да содржи .phar.
flags-
Знаменца за поминување до родителската класа RecursiveDirectoryIterator.
alias-
Алијас со кој оваа Phar архива треба да се повикува во повиците до стриминг функционалност.
Errors/Exceptions
). Ако повикот не успее, ќе врати BadMethodCallException ако се повика двапати, UnexpectedValueException ако Phar архивата не може да се отвори.
Примери
ако е овозможен колекторот за отпадоци, Phar::setAlias() example
<?php
try {
$p = new Phar('/path/to/my.phar', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME,
'my.phar');
} catch (UnexpectedValueException $e) {
die('Could not open my.phar');
} catch (BadMethodCallException $e) {
echo 'technically, this cannot happen';
}
// this works now
echo file_get_contents('phar://my.phar/example.txt');
// and works as if we had typed
echo file_get_contents('phar:///path/to/my.phar/example.txt');
?>