php zlib: How to dynamically create an in-memory zip files from string variables?

こ雲淡風輕ζ 提交于 2019-12-12 09:09:19

问题


this is what I need

$a=array('folder'=>'anyfolder','filename'=>'anyfilename','filedata'=>'anyfiledata');

I need to create a variable $zip with compressed data from $a and output this $zip into browser window with

header('Content-type: application/octetstream');
echo $zip;

All libs that I found, they pack files and create zip files physically on disk. I need to do it dynamically, using memory. Is there any examples of how to do it using pure php's zlib and without studying the zip format specifications?


UPD:
could it be done with CreateZIP class?

UPUPD:
Yes. it could =)


回答1:


Yes, CreateZIP class does it.

require_once('CreateZipFile.php');
$zip = new CreateZipFile;
$zip->addFile('anyfiledata', 'anyfilename');
$zip->addFile('anyfiledata2', 'anyfolder/anyfilename.anyext');
$zip->addDirectory('anyemptydirwouldbecreatedinthiszipfile');
header('Content-disposition: attachment; filename='.'zipfile.zip'.'');
header('Content-type: application/octetstream');
echo $zip->getZippedfile();
die();

great thanx to Er. Rochak Chauhan



来源:https://stackoverflow.com/questions/14712925/php-zlib-how-to-dynamically-create-an-in-memory-zip-files-from-string-variables

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