extensión extension descargarlo descargar crear carpeta addfile php zip
http://www.php.net/manual/en/function.zip-entry-read.php

extension - En PHP, ¿es posible inspeccionar el contenido de un archivo Zip sin extraer primero su contenido?



php zip descargar (4)

Como se encuentra en un comentario en http://www.php.net/ziparchive :

El siguiente código se puede usar para obtener una lista de todos los nombres de archivos en un archivo zip.

<?php $za = new ZipArchive(); $za->open(''theZip.zip''); for( $i = 0; $i < $za->numFiles; $i++ ){ $stat = $za->statIndex( $i ); print_r( basename( $stat[''name''] ) . PHP_EOL ); } ?>

He visto la clase ZipArchive en PHP que te permite leer archivos zip. Pero me pregunto si hay una forma de iterar su contenido sin extraer el archivo primero.


Pregunta repetida. Busca antes de publicar. Biblioteca PHP que puede listar contenidos de archivos zip / rar

<?php $rar_file = rar_open(''example.rar'') or die("Can''t open Rar archive"); $entries = rar_list($rar_file); foreach ($entries as $entry) { echo ''Filename: '' . $entry->getName() . "/n"; echo ''Packed size: '' . $entry->getPackedSize() . "/n"; echo ''Unpacked size: '' . $entry->getUnpackedSize() . "/n"; $entry->extract(''/dir/extract/to/''); } rar_close($rar_file); ?>


http://www.php.net/manual/en/function.zip-entry-read.php

<?php $zip = zip_open("test.zip"); if (is_resource($zip)) { while ($zip_entry = zip_read($zip)) { echo "<p>"; echo "Name: " . zip_entry_name($zip_entry) . "<br />"; if (zip_entry_open($zip, $zip_entry)) { echo "File Contents:<br/>"; $contents = zip_entry_read($zip_entry); echo "$contents<br />"; zip_entry_close($zip_entry); } echo "</p>"; } zip_close($zip); } ?>


I solved the problem like this. $zip = new /ZipArchive(); $zip->open(storage_path(''app/''.$request->vrfile)); $name = ''''; //looped through the zip files and got each index name of the files //since I only wanted the first name which is the folder name I break the loop //after updating the variable $name with the index name and that''s it for( $i = 0; $i < $zip->numFiles; $i++ ){ $filename = $zip->getNameIndex($i); var_dump($filename); $name = $filename; if ($i == 1){ break; } } var_dump($name);