如何识别zip错误

时间:2017-10-16 19:57:55

标签: php zip

当我尝试提取下载的zip文件时,它无法正常工作。如何识别错误?

响应失败;

谢谢。

档案位置 //home/www/boutique/includes/ClicShopping/Work/IceCat/daily.index.xml.gz

     public function ExtractZip() {

  if (is_file($this->selectFile())) {
    $zip = new \ZipArchive;

    if ($zip->open($this->selectFile()) === true) {

      $zip->extractTo($this->IceCatDirectory);
      $zip->close();

      echo 'file downloaded an unzipped';
    }
  } else {
    echo 'error no file found in ' . $this->selectFile();
  }
}

1 个答案:

答案 0 :(得分:0)

按照评论,有正确的功能

    public function ExtractGzip() {

// Raising this value may increase performance
      $buffer_size = 4096; // read 4kb at a time
      $out_file_name = str_replace('.gz', '', $this->selectFile());

// Open our files (in binary mode)
      $file = gzopen($this->selectFile(), 'rb');
      $out_file = fopen($out_file_name, 'wb');

// Keep repeating until the end of the input file
      while(!gzeof($file)) {
        // Read buffer-size bytes
        // Both fwrite and gzread and binary-safe
        fwrite($out_file, gzread($file, $buffer_size));
      }

// Files are done, close files
      fclose($out_file);
      gzclose($file);
    }