From a6781936dae880de841ce5f2d86d8b2f49233351 Mon Sep 17 00:00:00 2001 From: Sharon Rotgaizer <62396923+sharon846@users.noreply.github.com> Date: Sat, 15 Jul 2023 22:10:39 +0300 Subject: [PATCH] Fix ZIP viewer Support Zip extension viewer for php versions 8.0.0 above. --- tinyfilemanager.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/tinyfilemanager.php b/tinyfilemanager.php index 6f55502..f2fed26 100644 --- a/tinyfilemanager.php +++ b/tinyfilemanager.php @@ -2693,22 +2693,23 @@ function fm_get_directorysize($directory) { * @return array|bool */ function fm_get_zif_info($path, $ext) { - if ($ext == 'zip' && function_exists('zip_open')) { - $arch = @zip_open($path); - if ($arch) { + if ($ext == 'zip' && class_exists('ZipArchive')) { + $arch = new ZipArchive; + if ($arch->open($path)) { $filenames = array(); - while ($zip_entry = @zip_read($arch)) { - $zip_name = @zip_entry_name($zip_entry); - $zip_folder = substr($zip_name, -1) == '/'; - $filenames[] = array( - 'name' => $zip_name, - 'filesize' => @zip_entry_filesize($zip_entry), - 'compressed_size' => @zip_entry_compressedsize($zip_entry), + + for($i = 0; $i < $arch->numFiles; $i++ ){ + $stat = $arch->statIndex($i); + $zip_folder = substr($stat['name'], -1) == '/'; + $filenames[] = array( + 'name' => $stat['name'], + 'filesize' => $stat['size'], + 'compressed_size' => $stat['comp_size'], 'folder' => $zip_folder - //'compression_method' => zip_entry_compressionmethod($zip_entry), + //'compression_method' => $stat['comp_method'], ); - } - @zip_close($arch); + } + $arch->close(); return $filenames; } } elseif($ext == 'tar' && class_exists('PharData')) {