Reading a Zip File from a URL with PHP

I am looking for a good solution to read a zip file from a URL using php.

I checked the zip_open () function, but I never read anything about reading a file from another server.

Thank you very much

+4
source share
2 answers

The best way to do this is to copy the remote file to a temporary one:

$file = 'http://remote/url/file.zip'; $newfile = 'tmp_file.zip'; if (!copy($file, $newfile)) { echo "failed to copy $file...\n"; } 

Then you can do whatever you want with a temporary file:

  $zip = new ZipArchive(); if ($zip->open($newFile, ZIPARCHIVE::CREATE)!==TRUE) { exit("cannot open <$filename>\n"); } 
+4
source

Download the contents of the file (possibly using file_get_contents or copy to put it in your file system), then apply the decompression algorithm.

+1
source

Source: https://habr.com/ru/post/1343751/


All Articles