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