不确定这是否可行,但现在已成为一场学术斗争.
使用__halt_compiler()技巧将二进制数据嵌入到PHP文件中,我已经成功创建了一个自动打开的脚本,它将fseek()转换为__COMPILER_HALT_OFFSET__(不太难看,因为手册中记录了这个精确的示例)
无论如何,在我调用__halt_compiler()之后,我已经存储了一小块二进制ZIP数据(包含单个文件的单个文件夹,上面写着“hello world”)
我试图做的是将数据直接复制到php:// temp流,并成功完成(如果我倒回()和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');
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.
它一直在踢回错误代码11,我已经找到了no2文档(看起来像大多数其他可能的错误代码一样)
var_dump($zip); // int(11)
2 As @cweiske pointed out, error code 11 = ZipArchive::ER_OPEN, Can’t open file
这是我尝试使用php://临时流或其他可能的问题的结果吗?我也知道存在一种OOP方法(ZipArchive等人),但我想我会从基础开始.
有任何想法吗?