37 $info = &$this->getid3->info;
39 $info[
'fileformat'] =
'zip';
40 $info[
'zip'][
'encoding'] =
'ISO-8859-1';
43 $info[
'zip'][
'compressed_size'] = 0;
44 $info[
'zip'][
'uncompressed_size'] = 0;
45 $info[
'zip'][
'entries_count'] = 0;
48 $info[
'error'][] =
'File is larger than ' . round(PHP_INT_MAX / 1073741824) .
'GB, not supported by PHP';
53 $EOCDsearchCounter = 0;
54 while ($EOCDsearchCounter++ < 512) {
56 fseek($this->getid3->fp, -128 * $EOCDsearchCounter, SEEK_END);
57 $EOCDsearchData =
fread($this->getid3->fp, 128) . $EOCDsearchData;
59 if (strstr($EOCDsearchData,
'PK' .
"\x05\x06")) {
61 $EOCDposition = strpos($EOCDsearchData,
'PK' .
"\x05\x06");
62 fseek($this->getid3->fp,
63 (-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END);
66 fseek($this->getid3->fp,
67 $info[
'zip'][
'end_central_directory'][
'directory_offset'],
69 $info[
'zip'][
'entries_count'] = 0;
71 $info[
'zip'][
'central_directory'][] = $centraldirectoryentry;
72 $info[
'zip'][
'entries_count']++;
73 $info[
'zip'][
'compressed_size'] += $centraldirectoryentry[
'compressed_size'];
74 $info[
'zip'][
'uncompressed_size'] += $centraldirectoryentry[
'uncompressed_size'];
76 if ($centraldirectoryentry[
'uncompressed_size'] > 0) {
80 $centraldirectoryentry[
'uncompressed_size']));
84 if (
$info[
'zip'][
'entries_count'] == 0) {
85 $info[
'error'][] =
'No Central Directory entries found (truncated file?)';
90 if (!empty(
$info[
'zip'][
'end_central_directory'][
'comment'])) {
91 $info[
'zip'][
'comments'][
'comment'][] =
$info[
'zip'][
'end_central_directory'][
'comment'];
94 if (isset(
$info[
'zip'][
'central_directory'][0][
'compression_method'])) {
95 $info[
'zip'][
'compression_method'] =
$info[
'zip'][
'central_directory'][0][
'compression_method'];
97 if (isset(
$info[
'zip'][
'central_directory'][0][
'flags'][
'compression_speed'])) {
98 $info[
'zip'][
'compression_speed'] =
$info[
'zip'][
'central_directory'][0][
'flags'][
'compression_speed'];
100 if (isset(
$info[
'zip'][
'compression_method']) && (
$info[
'zip'][
'compression_method'] ==
'store') && !isset(
$info[
'zip'][
'compression_speed'])) {
101 $info[
'zip'][
'compression_speed'] =
'store';
113 if (
$info[
'zip'][
'compressed_size'] > (
$info[
'filesize'] - 46 - 22)) {
114 $info[
'error'][] =
'Warning: Truncated file! - Total compressed file sizes (' .
$info[
'zip'][
'compressed_size'] .
' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures (' . (
$info[
'filesize'] - 46 - 22) .
' bytes)';
116 $info[
'error'][] =
'Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete';
117 foreach (
$info[
'zip'][
'entries'] as $key => $valuearray) {
118 $info[
'zip'][
'files'][$valuearray[
'filename']] = $valuearray[
'uncompressed_size'];
125 $info[
'fileformat'] =
'';
126 $info[
'error'][] =
'Cannot find End Of Central Directory (truncated file?)';
138 $info = &$this->getid3->info;
140 $info[
'fileformat'] =
'zip';
142 $info[
'zip'][
'compressed_size'] = 0;
143 $info[
'zip'][
'uncompressed_size'] = 0;
144 $info[
'zip'][
'entries_count'] = 0;
146 rewind($this->getid3->fp);
148 $info[
'zip'][
'entries'][] = $fileentry;
149 $info[
'zip'][
'entries_count']++;
151 if (
$info[
'zip'][
'entries_count'] == 0) {
152 $info[
'error'][] =
'No Local File Header entries found';
157 $info[
'zip'][
'entries_count'] = 0;
159 $info[
'zip'][
'central_directory'][] = $centraldirectoryentry;
160 $info[
'zip'][
'entries_count']++;
161 $info[
'zip'][
'compressed_size'] += $centraldirectoryentry[
'compressed_size'];
162 $info[
'zip'][
'uncompressed_size'] += $centraldirectoryentry[
'uncompressed_size'];
164 if (
$info[
'zip'][
'entries_count'] == 0) {
165 $info[
'error'][] =
'No Central Directory entries found (truncated file?)';
171 $info[
'zip'][
'end_central_directory'] = $EOCD;
173 $info[
'error'][] =
'No End Of Central Directory entry found (truncated file?)';
178 if (!empty(
$info[
'zip'][
'end_central_directory'][
'comment'])) {
179 $info[
'zip'][
'comments'][
'comment'][] =
$info[
'zip'][
'end_central_directory'][
'comment'];
191 $info = &$this->getid3->info;
193 $info[
'zip'][
'compressed_size'] = 0;
194 $info[
'zip'][
'uncompressed_size'] = 0;
195 $info[
'zip'][
'entries_count'] = 0;
197 rewind($this->getid3->fp);
199 $info[
'zip'][
'entries'][] = $fileentry;
200 $info[
'zip'][
'entries_count']++;
201 $info[
'zip'][
'compressed_size'] += $fileentry[
'compressed_size'];
202 $info[
'zip'][
'uncompressed_size'] += $fileentry[
'uncompressed_size'];
204 if (
$info[
'zip'][
'entries_count'] == 0) {
205 $info[
'error'][] =
'No Local File Header entries found';
219 $LocalFileHeader[
'offset'] =
ftell($this->getid3->fp);
221 $ZIPlocalFileHeader =
fread($this->getid3->fp, 30);
226 if ($LocalFileHeader[
'raw'][
'signature'] != 0x04034B50) {
228 fseek($this->getid3->fp, $LocalFileHeader[
'offset'], SEEK_SET);
263 $LocalFileHeader[
'extract_version'] = sprintf(
'%1.1f',
264 $LocalFileHeader[
'raw'][
'extract_version'] / 10);
265 $LocalFileHeader[
'host_os'] = $this->
ZIPversionOSLookup(($LocalFileHeader[
'raw'][
'extract_version'] & 0xFF00) >> 8);
267 $LocalFileHeader[
'compressed_size'] = $LocalFileHeader[
'raw'][
'compressed_size'];
268 $LocalFileHeader[
'uncompressed_size'] = $LocalFileHeader[
'raw'][
'uncompressed_size'];
270 $LocalFileHeader[
'raw'][
'compression_method']);
271 $LocalFileHeader[
'last_modified_timestamp'] = $this->
DOStime2UNIXtime($LocalFileHeader[
'raw'][
'last_mod_file_date'],
272 $LocalFileHeader[
'raw'][
'last_mod_file_time']);
274 $FilenameExtrafieldLength = $LocalFileHeader[
'raw'][
'filename_length'] + $LocalFileHeader[
'raw'][
'extra_field_length'];
275 if ($FilenameExtrafieldLength > 0) {
276 $ZIPlocalFileHeader .=
fread($this->getid3->fp,
277 $FilenameExtrafieldLength);
279 if ($LocalFileHeader[
'raw'][
'filename_length'] > 0) {
280 $LocalFileHeader[
'filename'] = substr($ZIPlocalFileHeader, 30,
281 $LocalFileHeader[
'raw'][
'filename_length']);
283 if ($LocalFileHeader[
'raw'][
'extra_field_length'] > 0) {
284 $LocalFileHeader[
'raw'][
'extra_field_data'] = substr($ZIPlocalFileHeader,
285 30 + $LocalFileHeader[
'raw'][
'filename_length'],
286 $LocalFileHeader[
'raw'][
'extra_field_length']);
290 $LocalFileHeader[
'data_offset'] =
ftell($this->getid3->fp);
292 fseek($this->getid3->fp, $LocalFileHeader[
'raw'][
'compressed_size'],
295 if ($LocalFileHeader[
'flags'][
'data_descriptor_used']) {
296 $DataDescriptor =
fread($this->getid3->fp, 12);
308 return $LocalFileHeader;
317 $CentralDirectory[
'offset'] =
ftell($this->getid3->fp);
319 $ZIPcentralDirectory =
fread($this->getid3->fp, 46);
324 if ($CentralDirectory[
'raw'][
'signature'] != 0x02014B50) {
326 fseek($this->getid3->fp, $CentralDirectory[
'offset'], SEEK_SET);
379 $CentralDirectory[
'entry_offset'] = $CentralDirectory[
'raw'][
'local_header_offset'];
380 $CentralDirectory[
'create_version'] = sprintf(
'%1.1f',
381 $CentralDirectory[
'raw'][
'create_version'] / 10);
382 $CentralDirectory[
'extract_version'] = sprintf(
'%1.1f',
383 $CentralDirectory[
'raw'][
'extract_version'] / 10);
384 $CentralDirectory[
'host_os'] = $this->
ZIPversionOSLookup(($CentralDirectory[
'raw'][
'extract_version'] & 0xFF00) >> 8);
386 $CentralDirectory[
'compressed_size'] = $CentralDirectory[
'raw'][
'compressed_size'];
387 $CentralDirectory[
'uncompressed_size'] = $CentralDirectory[
'raw'][
'uncompressed_size'];
389 $CentralDirectory[
'raw'][
'compression_method']);
390 $CentralDirectory[
'last_modified_timestamp'] = $this->
DOStime2UNIXtime($CentralDirectory[
'raw'][
'last_mod_file_date'],
391 $CentralDirectory[
'raw'][
'last_mod_file_time']);
393 $FilenameExtrafieldCommentLength = $CentralDirectory[
'raw'][
'filename_length'] + $CentralDirectory[
'raw'][
'extra_field_length'] + $CentralDirectory[
'raw'][
'file_comment_length'];
394 if ($FilenameExtrafieldCommentLength > 0) {
395 $FilenameExtrafieldComment =
fread($this->getid3->fp,
396 $FilenameExtrafieldCommentLength);
398 if ($CentralDirectory[
'raw'][
'filename_length'] > 0) {
399 $CentralDirectory[
'filename'] = substr($FilenameExtrafieldComment,
401 $CentralDirectory[
'raw'][
'filename_length']);
403 if ($CentralDirectory[
'raw'][
'extra_field_length'] > 0) {
404 $CentralDirectory[
'raw'][
'extra_field_data'] = substr($FilenameExtrafieldComment,
405 $CentralDirectory[
'raw'][
'filename_length'],
406 $CentralDirectory[
'raw'][
'extra_field_length']);
408 if ($CentralDirectory[
'raw'][
'file_comment_length'] > 0) {
409 $CentralDirectory[
'file_comment'] = substr($FilenameExtrafieldComment,
410 $CentralDirectory[
'raw'][
'filename_length'] + $CentralDirectory[
'raw'][
'extra_field_length'],
411 $CentralDirectory[
'raw'][
'file_comment_length']);
415 return $CentralDirectory;
424 $EndOfCentralDirectory[
'offset'] =
ftell($this->getid3->fp);
426 $ZIPendOfCentralDirectory =
fread($this->getid3->fp, 22);
431 if ($EndOfCentralDirectory[
'signature'] != 0x06054B50) {
433 fseek($this->getid3->fp, $EndOfCentralDirectory[
'offset'], SEEK_SET);
459 if ($EndOfCentralDirectory[
'comment_length'] > 0) {
460 $EndOfCentralDirectory[
'comment'] =
fread($this->getid3->fp,
461 $EndOfCentralDirectory[
'comment_length']);
464 return $EndOfCentralDirectory;
476 $ParsedFlags[
'encrypted'] = (bool) ($flagbytes & 0x0001);
478 switch ($compressionmethod) {
480 $ParsedFlags[
'dictionary_size'] = (($flagbytes & 0x0002) ? 8192 : 4096);
481 $ParsedFlags[
'shannon_fano_trees'] = (($flagbytes & 0x0004) ? 3 : 2);
486 switch (($flagbytes & 0x0006) >> 1) {
488 $ParsedFlags[
'compression_speed'] =
'normal';
491 $ParsedFlags[
'compression_speed'] =
'maximum';
494 $ParsedFlags[
'compression_speed'] =
'fast';
497 $ParsedFlags[
'compression_speed'] =
'superfast';
502 $ParsedFlags[
'data_descriptor_used'] = (bool) ($flagbytes & 0x0008);
515 static $ZIPversionOSLookup =
array(
516 0 =>
'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)',
522 6 =>
'OS/2 H.P.F.S.',
526 10 =>
'Windows NTFS',
531 15 =>
'Alternate MVS',
536 return (isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] :
'[unknown]');
547 static $ZIPcompressionMethodLookup =
array(
558 10 =>
'PKWARE Date Compression Library Imploding' 561 return (isset($ZIPcompressionMethodLookup[$index]) ? $ZIPcompressionMethodLookup[$index] :
'[unknown]');
579 $UNIXday = ($DOSdate & 0x001F);
580 $UNIXmonth = (($DOSdate & 0x01E0) >> 5);
581 $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980;
590 $UNIXsecond = ($DOStime & 0x001F) * 2;
591 $UNIXminute = (($DOStime & 0x07E0) >> 5);
592 $UNIXhour = (($DOStime & 0xF800) >> 11);
594 return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth,
595 $UNIXday, $UNIXyear);
GetId3() by James Heinrich info@getid3.org //.
static CreateDeepArray($ArrayPath, $Separator, $Value)
getZIPentriesFilepointer()
GetId3() by James Heinrich info@getid3.org //.
ZIPparseCentralDirectory()
ZIPparseLocalFileHeader()
static DOStime2UNIXtime($DOSdate, $DOStime)
fseek($bytes, $whence=SEEK_SET)
static ZIPversionOSLookup($index)
array $ZIPversionOSLookup
ZIPparseEndOfCentralDirectory()
Create styles array
The data for the language used.
static array_merge_clobber($array1, $array2)
getZIPHeaderFilepointerTopDown()
static LittleEndian2Int($byteword, $signed=false)
static ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod)
static intValueSupported($num)
null $hasINT64
static ZIPcompressionMethodLookup($index)
array $ZIPcompressionMethodLookup