PHP压缩文件到zip [英] PHP compress files into zip
问题描述
Hello there
okay所以这是我有一个文件夹,我的mp3文件存储为单个下载,现在我想要一个功能,你可以在一个压缩文件夹中一次下载所有的mp3文件。是否可能使用php(或任何真正的,但如果不是PHP,然后请彻底解释)从该文件夹的所有文件压缩或者我只需要重新上传所有的mp3再次压缩格式?
只是为了演示如何使用未记录的addGlob zipArchive类:
$ zipFile = dirname(__ FILE __)/ myMP3s.zip;
$ zipArchive = new ZipArchive();
if(!$ zipArchive-> open($ zipFile,ZIPARCHIVE :: OVERWRITE))
die(无法创建archive\\\
$ zipArchive-> addGlob(dirname(__ FILE __)。/ *。mp3);
if(!$ zipArchive-> status == ZIPARCHIVE :: ER_OK)
echo无法将本地文件写入zip\\\
;
$ zipArchive-> close();
Hello there okay so this is the deal i have a folder where my mp3 files are stored for single download, and now i want a feature where you can download all the mp3s at once in a zipped folder. Is it possible to zip all the files from that folder using php ( or anything really but if not PHP then please explain thoroughly) or would i have to just re-upload all the mp3s again in zipped format?
Thanks you so much.
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();
这篇关于PHP压缩文件到zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!