PHP

HOW TO READ ZIP FILES IN PHP

(quick guide & examples)

OPEN ZIP FILE $zip = new ZipArchive; $zip->open("MY.ZIP", ZipArchive::RDONLY);

USING ZIP ARCHIVE (A)

01

FILES & FOLDERS IN ZIP $total = $zip->count(); for ($i=0; $i<$total; $i++) { print_r($zip->statIndex($i)); }

READ FILE $data = $zip->getFromIndex(0); $data = $zip->getFromName("FILE.TXT"); $zip->close();

OPEN ZIP FILE $zip = zip_open("FILE.ZIP"); while ($entry = zip_read($zip)) {   FILE NAME & SIZE   $name = zip_entry_name($entry);   $size = zip_entry_filesize($entry);

LEGACY READ ZIP

02

  READ FILE CONTENT   zip_entry_open($zip, $entry);   $data = zip_entry_read($entry);   zip_entry_close($entry); } zip_close($zip);