PHP zip_open() 和 php://temp,好像打不开 [英] PHP zip_open() and php://temp, can't seem to open

查看:29
本文介绍了PHP zip_open() 和 php://temp,好像打不开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定这是否可行,但现在已经成为学术斗争.

使用 __halt_compiler() 技巧将二进制数据嵌入到 PHP 文件中,我已经成功创建了一个自打开脚本,它将 fseek() 转换为 __COMPILER_HALT_OFFSET__(不太难看,因为手册中记录了这个精确的示例)

无论如何,在我调用 __halt_compiler() 之后,我已经存储了一小块二进制 ZIP 数据(一个包含单个文件的文件夹,上面写着hello world")代码>

我尝试做的是将数据直接复制到 php://temp 流中,并且已经成功完成(如果我 rewind()passthru() 临时流句柄,它转储数据)

$php = fopen(__FILE__, 'rb');$tmp = fopen('php://temp', 'r+b');fseek($php, __COMPILER_HALT_OFFSET__);stream_copy_to_stream($php, $tmp);

我的问题是现在尝试使用 zip_open()

打开 php://temp1

$zip = zip_open('php://temp');

<块引用>

1从我所见(尽管存在其他可能性,例如 zip_open() 缺乏流支持),这里的问题是php://memoryphp://temp 数据流在句柄之间的固有非永久性.如果这可以解决,也许实际上是可能的.

它不断踢回错误代码 11,我发现 没有2 文档(似乎,就像大多数其他可能的错误代码)

var_dump($zip);//整数(11)

<块引用>

2 正如@cweiske 指出的,错误代码11 = ZipArchive::ER_OPEN无法打开文件

这是我尝试使用 php://temp 流的结果,还是其他一些可能的问题?我也知道存在 OOP 方法(ZipArchive 等.)但我想我会从基础开始.

有什么想法吗?

解决方案

11 是常量ZIPARCHIVE::ER_OPEN,手册中描述了

<块引用>

无法打开文件

请注意,手册没有没有说明可以使用流包装器.

<小时>

请考虑使用 PHP 的 phar 扩展 - 它可以满足您的需求,并且经过充分测试.

Not sure if this is possible, but it's become an academic struggle now.

Using the __halt_compiler() trick to embed binary data in a PHP file, I've successfully created a self-opening script which will fseek() to __COMPILER_HALT_OFFSET__ (not too hard seeing as this precise example is documented in the manual)

Anyways, I've stored a small lump of binary ZIP data (a single folder containing a single file that says "hello world") after my call to __halt_compiler()

What I've tried to do is copy the data directly to the php://temp stream, and have done so with success (if I rewind() and passthru() the temporary stream handle, it dumps the data)

$php = fopen(__FILE__, 'rb');
$tmp = fopen('php://temp', 'r+b');
fseek($php, __COMPILER_HALT_OFFSET__);
stream_copy_to_stream($php, $tmp);

My problem comes with trying to now open php://temp1 with zip_open()

$zip = zip_open('php://temp');

1From what I can see (despite other such possibilities as lack of stream support with zip_open()) the problem here is the inherent non-permanence of data in php://memory and php://temp streams between handles. If this can be worked around, perhaps it is in fact possible.

It keeps kicking back error code 11, which I have found no2 documentation on (seemingly, like most other possible error codes)

var_dump($zip); // int(11)

2 As @cweiske pointed out, error code 11 = ZipArchive::ER_OPEN, Can't open file

Is this consequence to my attempt at using the php://temp stream, or some other possible issue? I'm also aware there exists an OOP approach (ZipArchive, et al.) but I figured I'd start with the basics.

Any ideas?

解决方案

11 is the constant ZIPARCHIVE::ER_OPEN, which the manual describes with

Can't open file

Note that the manual does not state that stream wrappers may be used.


Please think about using PHP's phar extension - it does what you want, and is well tested.

这篇关于PHP zip_open() 和 php://temp,好像打不开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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