1

I need to read files from ZIP archives with PHP. And my zip is not on the disk. It is accessible with http url. There is the extension ZipArchive . It works fine if a file is on disk . Is it possible to use this extension with some opened resource instead of opening a file by path?

Important note, i can not download a zip file temporary to disk. I can work only with the file remotely.

If not ZipArchive, maybe there are other similar libraries for Zip that can read from stream?

There is simple example which doesn't work.

$zip = new ZipArchive();
$fh = fopen('zipfiles/1.zip','r');

$status = $zip->open($fh);

if ($status !== TRUE) {
    exit("Error $status");
}

echo "Number of files: ".$zip->numFiles;

But this one works fine

$zip = new ZipArchive();

$status = $zip->open('zipfiles/1.zip');

if ($status !== TRUE) {
    exit("Error $status");
}

echo "Number of files: ".$zip->numFiles;
Roman Gelembjuk
  • 1,797
  • 2
  • 25
  • 50
  • [See this](https://stackoverflow.com/questions/4165289/create-a-zip-file-using-php-class-ziparchive-without-writing-the-file-to-disk) – Rain Jul 22 '21 at 09:37
  • That examples are writing Zip archives with a stream. I need same for for reading. My Zip is stored on web server, i can access it with url like http://host.com/myarc.zip And i want to extract files from it without saving this file to a disk. – Roman Gelembjuk Jul 22 '21 at 10:20

0 Answers0