PHP Doku:: Öffnet eine bzip2-komprimierte Datei - function.bzopen.html

Verlauf / Chronik / History: (17) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzErweiterungen zur Datenkompression und ArchivierungBzip2Bzip2 Funktionenbzopen

Ein Service von Reinhard Neidl - Webprogrammierung.

Bzip2 Funktionen

<<bzflush

bzread>>

bzopen

(PHP 4 >= 4.0.4, PHP 5)

bzopenÖffnet eine bzip2-komprimierte Datei

Beschreibung

resource bzopen ( string $filename , string $mode )

Öffnet eine bzip2-Datei (.bz2) zum Lesen oder Schreiben.

Parameter-Liste

filename

Name der zu öffnenden Datei.

mode

Ähnlich zur Funktion fopen() wird 'r' für lesenden und 'w' für schreibenden Zugriff unterstützt. Andere Werte führen dazu, daß bzopen FALSE zurückgibt.

Rückgabewerte

Wenn das Öffnen fehlschlägt, gibt bzopen() FALSE zurück, andernfalls wird ein Zeiger auf die geöffnete Datei zurückgegeben.

Beispiele

Beispiel #1 bzopen()-Beispiel

<?php

$file 
"/tmp/foo.bz2";
$bz bzopen($file"r") or die("$file konnte nicht zum Lesen geöffnet werden");

bzclose($bz);

?>

Siehe auch


2 BenutzerBeiträge:
- Beiträge aktualisieren...
KrazyBox
31.12.2008 2:44
In some circumstances, you may want to send a bzip2 stream to the client.

To do this, you need only do:

<?php
ob_flush
();
$bz = bzopen('php://stdout', 'w');
bzwrite($bz, 'some input here');
bzclose($bz);
?>

However, please note, because you are using STDOUT, you need to ob_flush() before actually writing to the stream. Otherwise, you might be sending data before the headers, which will cause errors on both server and client ends, in most cases.

You might be able to use php://output rather than php://stdout, however in my tests (with Linux), php://output doesn't actually work - at all.
Jille at quis dot cx dot spam dot to dot my dot devnull
19.03.2008 22:11
Warning!

the example show above is _not_ working in every case!
This example will continue reading until there is no more data:

<?PHP
      $bz
=bzopen('foo.bz2', 'r');
     
$data="";
      do {
       
$line=bzread($bz, 8092);
        if(
$line!==false)
         
$data.=$line;
      }
      while(
$line);
     
bzclose($bz);
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)