CakeFest 2024: The Official CakePHP Conference

readgzfile

(PHP 4, PHP 5, PHP 7, PHP 8)

readgzfilegz ファイルを出力する

説明

readgzfile(string $filename, int $use_include_path = 0): int|false

ファイルを読み込み、解凍し、標準出力に書き込みます。

readgzfile()は、gzip フォーマットでないファイルの読込にも使用可能です。この場合、 readgzfile() はファイルを解凍せずに直接読込みます。

パラメータ

filename

ファイル名を指定します。このファイルはファイルシステムからオープンされ、 内容は標準出力に書き込まれます。

use_include_path

include_path にあるファイルも検索したい場合、このオプションパラメータを 1 に設定してください。

戻り値

成功時は、ファイルから読み込んだ (解凍された) データのバイト数を返します。 失敗した場合に false を返します

エラー / 例外

失敗したときは E_WARNING が発生します。

参考

  • gzpassthru() - gzファイルへのポインタから残りのデータ全部を出力する
  • gzfile() - gzファイル全体を配列に読み込む
  • gzopen() - gz ファイルを開く

add a note

User Contributed Notes 1 note

up
-4
glennh at webadept dot net
20 years ago
This is a rather simple example of usage for this function, but it does work, and it solved a problem I was using with old browsers accessing gzipped files.

<?PHP

// first we need to stop the server from sending any headers at all.
ob_start();

readgzfile("test.html.gz"); // read the file and output directly to
the browser
// non compressed data from the
file

ob_end_flush
(); // let the headers go//

?>

There is no need for any html formating if the source file is an HTML formated page, such as the ones I'm using are. Checking the browser version, sends either the gzip file directly, or sends the browser to a page like this, which does the work for it. Well done simple function.

My server is running PHP 4.2.2 on Linux Redhat version 9 and
Apache 2.0.40
To Top