webForumDet fria alternativet

PHP och unzip

0 svar · 485 visningar · startad av Asa

AsaMedlem sedan dec. 20011 934 inlägg
#1

Jag har denna koden för att zippa upp en fil men vet inte var jag ska lägga koden som skapar mapparna i zippen. Koden här:

<?php
$zip = zip_open("zip.zip");
if ($zip) {
  while ($zip_entry = zip_read($zip)) {
    $fp = fopen("zip/".zip_entry_name($zip_entry), "w");
    if (zip_entry_open($zip, $zip_entry, "r")) {
      $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
      fwrite($fp,"$buf");
      zip_entry_close($zip_entry);
      fclose($fp);
    }
  }
  zip_close($zip);
}
?>

Lite info från skaparen och skapa mapparna ifrån zppen vet jag ej hur jag gör...

Zip files usually have more than one file inside them, so when you open a zip file you need to go through each file. That is what the zip_read and zip_entry_read functions are doing.

zip_read is getting all the info for each file, and zip_entry_read is getting the file contents from the info returned by zip_read.

zip_entry_name returns the path of the file within the zip. If the file is in a folder inside the zip, you’ll need to create the directory before trying to write the file.

Genererad på 359 ms · cache AV · v20260730165559-full.f96bc7eb