在百度搜索到的 PharData 类和 ZipArchive 都是解压不了 .gz 的文件的,后来在 google 搜索到解决方法,问题解决。
try { $phar = new PharData($save_url, Phar::CURRENT_AS_FILEINFO | Phar::KEY_AS_FILENAME); $phar->extractTo($path, null, true); } catch (UnexpectedValueException $e) { die('Could not open'); } catch (BadMethodCallException $e) { echo 'technically, this cannot happen'; }
$zip = new ZipArchive(); $zip_open = $zip->open($save_url); var_dump($zip_open); if(true===$zip_open){ $zip->extractTo('./Zip/'); $zip->close(); }
$buffer_size = 4096; $out_file_name = str_replace('.gz', '', $save_url); $file = gzopen($save_url, 'rb'); $out_file = fopen($out_file_name, 'wb'); while(!gzeof($file)) { fwrite($out_file, gzread($file, $buffer_size)); } fclose($out_file); gzclose($file);
http://stackoverflow.com/questions/3293121/how-can-i-unzip-a-gz-file-with-php