ZipArchiveReader.php 886 Bytes
<?php
/**
 * Created by PhpStorm.
 * User: Tsurkanov
 * Date: 03.11.2015
 * Time: 15:12
 */

namespace common\components\archives;


class ZipArchiveReader extends  ArchiveReader {

    protected $resource;
    public  function open( $file, $password = '' ){
        $zip = new \ZipArchive;
        $this->resource = $zip->open( $file );
        if ($this->resource === FALSE)
            throw new \Exception("Failed opening zip file");
    }

    public  function extractTo( $destination){

            $this->resource->extractTo($destination);

        for ($i = 0; $i < $this->resource->numFiles; $i++) {
            $filename = $this->resource->getNameIndex($i);
            $this->setExtractedFiles($filename, pathinfo($filename, PATHINFO_EXTENSION));
        }

        $this->resource->close();
    }
    public static  function getExtension(){
        return 'rar';
    }




}