Blame view

common/components/archives/RarArchiveReader.php 889 Bytes
8f043ab6   Mihail   add classes to wo...
1
2
3
4
5
6
7
8
  <?php
  /**
   * Created by PhpStorm.
   * User: Tsurkanov
   * Date: 03.11.2015
   * Time: 15:12
   */
  
c4da20f0   Mihail   temp commit - tes...
9
  namespace common\components\archives;
8f043ab6   Mihail   add classes to wo...
10
11
12
13
  
  
  class RarArchiveReader extends  ArchiveReader {
  
c4da20f0   Mihail   temp commit - tes...
14
      protected $resource;
8f043ab6   Mihail   add classes to wo...
15
      public  function open( $file, $password = '' ){
c4da20f0   Mihail   temp commit - tes...
16
17
18
19
  
          $this->resource = rar_open( $file, $password );
          if ($this->resource === FALSE)
              throw new \Exception("Failed opening rar file");
8f043ab6   Mihail   add classes to wo...
20
21
22
      }
  
      public  function extractTo( $destination){
c4da20f0   Mihail   temp commit - tes...
23
24
25
26
27
28
29
30
31
          $list = rar_list($this->resource);
  
          foreach($list as $file) {
              $entry = rar_entry_get($this->resource, $file);
              $entry->extract($destination);
  
              $this->setExtractedFiles($entry->getName(), pathinfo($entry->getName(), PATHINFO_EXTENSION));
  
          }
8f043ab6   Mihail   add classes to wo...
32
  
c4da20f0   Mihail   temp commit - tes...
33
          rar_close($this->resource);
8f043ab6   Mihail   add classes to wo...
34
35
36
37
38
39
40
41
42
      }
      public static  function getExtension(){
          return 'rar';
      }
  
  
  
  
  }