(PHP >= 8.6.0)
ZipArchive::openString — Open a ZIP archive held in a string
Opens a ZIP archive whose contents are held in a string, instead of in a file. Called without arguments, it starts a new, empty archive in memory. Use ZipArchive::closeString() to get the resulting archive back as a string.
dataThe contents of an existing ZIP archive. The default, an empty string, creates a new archive.
flags
A bitmask of flags, as for ZipArchive::open(),
for example ZipArchive::CHECKCONS.
ZipArchive::EXCL always fails with
ZipArchive::ER_EXISTS, as there is no file, and
ZipArchive::CREATE has no effect.
Returns true on success or the error code on failure, for example
ZipArchive::ER_NOZIP if data
is not a ZIP archive.
Örnek 1 Creating an archive in memory
<?php
$zip = new ZipArchive;
$zip->openString();
$zip->addFromString('hello.txt', "Hello\n");
$bytes = $zip->closeString();
// $bytes can be sent to a client or stored, and read back later.
$zip = new ZipArchive;
var_dump($zip->openString($bytes));
var_dump($zip->getFromName('hello.txt'));
?>Yukarıdaki örneğin çıktısı:
bool(true) string(6) "Hello "