15

CodeIgniter を使用していますが、ファイルの解凍方法がわかりません。

4

5 に答える 5

48

PHP 自体には、gzip ファイルを処理するための関数が多数あります。

圧縮されていない新しいファイルを作成する場合は、次のようになります。

注: これは、ターゲット ファイルが最初に存在するかどうかを確認したり、入力ファイルを削除したり、エラー チェックを行ったりしません。これを本番コードで使用する前に、これらを修正する必要があります。

// This input should be from somewhere else, hard-coded in this example
$file_name = 'file.txt.gz';

// Raising this value may increase performance
$buffer_size = 4096; // read 4kb at a time
$out_file_name = str_replace('.gz', '', $file_name);

// Open our files (in binary mode)
$file = gzopen($file_name, 'rb');
$out_file = fopen($out_file_name, 'wb');

// Keep repeating until the end of the input file
while(!gzeof($file)) {
    // Read buffer-size bytes
    // Both fwrite and gzread and binary-safe
    fwrite($out_file, gzread($file, $buffer_size));
}

// Files are done, close files
fclose($out_file);
gzclose($file);

注: これは gzipのみを扱います。タールは扱っていません。

于 2010-07-20T18:45:02.827 に答える
3

ZlibCompression拡張機能によって実装された関数を使用します。

このスニペットは、拡張機能から利用できるようになったいくつかの機能の使用方法を示しています。

// open file for reading
$zp = gzopen($filename, "r");

// read 3 char
echo gzread($zp, 3);

// output until end of the file and close it.
gzpassthru($zp);
gzclose($zp);
于 2010-07-20T18:36:23.670 に答える
2

Unzip ライブラリをダウンロードして 、またはライブラリをインクルードしますautoloadunzip

$this->load->library('unzip');
于 2010-07-20T18:32:44.167 に答える