具体代码参考如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | //获取当前目录 $dir = dirname( __FILE__ ); // 压缩文件 $temp_file = $dir . '/web.zip' ; // 解压文件 $zip = new ZipArchive(); if ( $zip ->open( $temp_file ) !== TRUE) { throw new Exception( '无法打开压缩文件' ); } // 创建解压目录 $extract_path = $dir ; // 执行解压 if (! $zip ->extractTo( $extract_path )) { throw new Exception( '解压失败' ); } $zip ->close(); // 获取解压文件列表 $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $extract_path ), RecursiveIteratorIterator::LEAVES_ONLY ); // 显示结果 echo '<h3>解压成功!文件列表:</h3>' ; foreach ( $files as $file ) { if (! $file ->isDir()) { echo $file ->getPathname() . '<br>' ; } } |
相关文章