PHP compress files into zip

江枫思渺然 提交于 2019-12-01 12:04:59

Just to demonstrate use of the undocumented addGlob() method of the zipArchive class:

$zipFile = dirname(__FILE__)."/myMP3s.zip";
$zipArchive = new ZipArchive();

if (!$zipArchive->open($zipFile, ZIPARCHIVE::OVERWRITE))
    die("Failed to create archive\n");

$zipArchive->addGlob(dirname(__FILE__)."/*.mp3");
if (!$zipArchive->status == ZIPARCHIVE::ER_OK)
    echo "Failed to write local files to zip\n";

$zipArchive->close();

There are several PHP libraries for compression. Have you tried them?

http://php.net/manual/en/book.zip.php

Mark Baker's example looks good, read up if you want to learn or need something more specific.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!