PHP 8.5.0 Alpha 1 available for testing

Utilizar los archivos Phar : el flujo phar

El flujo Phar soporta totalmente fopen() para las lecturas/escrituras (no las concatenaciones), unlink(), stat(), fstat(), fseek(), rename(), y las operaciones de flujo sobre los directorios opendir(), y rmdir() y mkdir().

La compresión y los metadatos individuales por fichero pueden también ser manipulados dentro del archivo Phar utilizando los contextos de flujo:

<?php
$context
= stream_context_create(array('phar' =>
array(
'compress' => Phar::GZ)),
array(
'metadata' => array('user' => 'cellog')));
file_put_contents('phar://mon.phar/unfichero.php', 0, $context);
?>

El flujo phar no actúa sobre los ficheros remotos y no puede considerar los ficheros remotos, etc... incluso si las opciones INI allow_url_fopen y allow_url_include están desactivadas.

Aunque es posible crear archivos phar desde cero utilizando solo las operaciones sobre los flujos, es preferible utilizar la funcionalidad incluida en la clase Phar. El flujo es mejor utilizado para las operaciones de lectura.

add a note

User Contributed Notes 2 notes

up
4
staff at pro-unreal dot de
14 years ago
Please note that the phar stream wrapper does not work with any glob.
When you decide to move your project to phar archives you need to consider this.

The following won't work:
<?php
glob
('phar://some.phar/*');
new
DirectoryIterator('glob://phar://some.phar/*');
?>

While the following will work:
<?php
new DirectoryIterator('phar://some.phar/');
?>
up
0
carl at dot dot com
14 years ago
Some Examples of how to use the stream wrapper would be really helpful.
My floundering attempts reveal only the following:

<?php
$p
= new PharData(dirname(__FILE__).'/phartest.zip', 0,'phartest',Phar::ZIP) ;

$p->addFromString('testfile.txt',
'this is just some test text');

// This works
echo file_get_contents('phar://phartest.zip/testfile.txt');

//This Fails
file_put_contents('phar://phartest.zip/testfile.txt',
'Thist is text for testfile.txt');

$context = stream_context_create(
array(
'phar' =>array('compress' =>Phar::ZIP))
) ;

//This Fails
file_put_contents(
'phar://phartest.zip/testfile.txt',
'Thist is text for testfile.txt',0,$context);

// This works but only with 'r' readonly mode.
$f = fopen(
'phar://C:\\Inetpub\\wwwroot\\PACT\\test\\phartest.zip\\testfile.txt',
'r') ;
?>
To Top