开发者

PHP zip_open() and php://temp, can't seem to open

开发者 https://www.devze.com 2023-03-25 19:14 出处:网络
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 w

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://tem开发者_如何学Gop 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消