Not sure if this is possible, but now it is becoming an academic struggle.
Using the __halt_compiler() trick to embed binary data in a PHP file, I successfully created a self-expanding script that will be fseek() until __COMPILER_HALT_OFFSET__ (it's not too hard to see how this exact example is documented in the manual)
Anyway, I wrote down a small piece of binary ZIP data (one folder containing one file that says hello world) after my call to __halt_compiler()
What I tried to do was copy the data directly to the php://temp stream and do it with success (if I rewind() and passthru() temporary stream handle, it unloads 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 is trying to open php://temp 1 with zip_open()
$zip = zip_open('php://temp');
1 From what I see (despite other features such as the lack of thread support using zip_open() ), the problem here is the inherent data instability in php://memory and php://temp threads between the handles. If this can be circumvented, perhaps it is indeed possible.
It continues to override error code 11 , which I found in documentation no.2 (it looks like most other possible error codes)
var_dump($zip); // int(11)
2 As @cweiske noted, error code 11 = ZipArchive::ER_OPEN , cannot open file
Is this the result of my attempt to use the php://temp stream or some other possible problem? I also know that there is an OOP approach ( ZipArchive et al.), But I decided that I would start with the basics.
Any ideas?