php zlib:如何从字符串变量动态创建内存中的zip文件? [英] php zlib: How to dynamically create an in-memory zip files from string variables?

查看:268
本文介绍了php zlib:如何从字符串变量动态创建内存中的zip文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我需要的

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

我需要使用$ a的压缩数据创建一个变量$ zip,并将该$ zip输出到浏览器窗口与

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;

我发现的所有libs都包装文件,并在磁盘上物理创建zip文件。我需要动态地使用内存。有没有使用纯php的zlib和没有研究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:

可以用 CreateZIP 类?

UPUPD:

是的。它可以=)

UPUPD:
Yes. it could =)

推荐答案

是的, CreateZIP 类。

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

great thanx to Er. Rochak Chauhan

这篇关于php zlib:如何从字符串变量动态创建内存中的zip文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆