zoukankan      html  css  js  c++  java
  • php 解压 .gz 文件

    在百度搜索到的 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

  • 相关阅读:
    线性表——(2)单向链表
    线性表——(1)顺序表
    UVa 1592 数据库
    UVa 12096 集合栈计算机
    Python 协程
    Python 多线程及进程
    Python 日志(Log)
    Python 函数式编程
    Python基础
    DB2 获取前两天的数据
  • 原文地址:https://www.cnblogs.com/chy1000/p/4754882.html
Copyright © 2011-2022 走看看