前の記事 ≪:Flashムービーのサイズをブラウザ幅に応じて自動調整できるJSライブラ...
次の記事 ≫:Ext2.0のアルファ版がリリース

PHPでファイルのZIP圧縮をする際に便利に使えるクラスライブラリ

2007年10月02日-はてなブックマーク

スポンサード リンク
[PR] 英単語を忘却曲線アプリを使って超効率よく記憶する方法
Tutorial: Create a zip file from folders on the fly - Web Development Blog
For a future project I needed these days some easy to use zip or gzip class to create a zip file from files / folders inside a specified directory.

PHPでファイルのZIP圧縮をする際に便利に使えるクラスライブラリ。
次のように、圧縮対象のディレクトリや、複数ファイルをアーカイブに登録するためのメソッドが用意されています。

$createZip = new createDirZip;
$createZip->addDirectory(‘themes/’);
$createZip->get_files_from_folder(‘blog/wp-content/themes/’, ‘themes/’);

次のようなコードでダウンロードを実行します。

$fileName = ‘tmp/archive.zip’;
$fd = fopen ($fileName, ‘wb’);
$out = fwrite ($fd, $createZip->getZippedfile());
fclose ($fd);

$createZip->forceDownload($fileName);
@unlink($fileName);

PHPでサーバ側のファイルをバックアップする場合に便利に使うことが出来そうです。

関連の記事検索:PHP, ライブラリ, zip
スポンサード リンク

By.KJ : 2007年10月02日 10:04 livedoor Readerで購読 Twitterに投稿

間違いの指摘をしていただける方はメール、あるいはTwitter/FBでお願いします(クリック)