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: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70:
<?php
class Zip_Filter extends Archive_Base
{
public static function extract_files($archive, $dest, array $file = null, ?array $opts = array())
{
$zip = new ZipArchive();
if (!$zip->open($archive)) {
return error("unable to open archive `%s': ",
$archive,
$zip->getStatusString()
);
}
$zip->extractTo($dest, $file);
$zip->close();
return true;
}
public static function list_files($archive, ?array $opts = array())
{
$proc = parent::exec('/usr/bin/unzip -ll -- %s',
$archive,
array(1, 0));
$proc = explode("\n", trim($proc['output']));
$files = array();
foreach ($proc as $line) {
if (!preg_match(Regex::FILE_HDR_ZIP, $line, $matches)) {
continue;
}
list ($null, $size, $method, $packed_size, $date, $crc, $file_name) = $matches;
$files[] = array(
'file_name' => $file_name,
'file_type' => $file_name[strlen($file_name) - 1] == '/' ? 'dir' : 'file',
'can_read' => true,
'can_write' => true,
'can_execute' => true,
'size' => !$size ? 4095 : $size,
'packed_size' => $packed_size,
'crc' => $crc,
'link' => 0,
'date' => strtotime($date)
);
}
return $files;
}
}
?>