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でサーバ側のファイルをバックアップする場合に便利に使うことが出来そうです。