LoginSignup
4
0

More than 5 years have passed since last update.

PHPのZipArchiveで空のzipファイルを作成する

Posted at

はじめに

中身が入っていないzipファイルが必要になった時にちょっと戸惑った。

方法

add〜を呼び出さずにopen/closeするだけだとzipファイルは生成されません。
そこで、下記のようにaddEmptyDir() で相対パスでカレントディレクトリを指定します。

$zip = new \ZipArchive();
$zip->open('/foo/bar.zip', \ZipArchive::CREATE);
$zip->addEmptyDir('.');
$zip->close()
4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0