module.archive.zip.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at http://getid3.sourceforge.net //
  5. // or http://www.getid3.org //
  6. /////////////////////////////////////////////////////////////////
  7. // See readme.txt for more details //
  8. /////////////////////////////////////////////////////////////////
  9. // //
  10. // module.archive.zip.php //
  11. // module for analyzing pkZip files //
  12. // dependencies: NONE //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. class getid3_zip
  16. {
  17. function getid3_zip(&$fd, &$ThisFileInfo) {
  18. $ThisFileInfo['fileformat'] = 'zip';
  19. $ThisFileInfo['zip']['encoding'] = 'ISO-8859-1';
  20. $ThisFileInfo['zip']['files'] = array();
  21. $ThisFileInfo['zip']['compressed_size'] = 0;
  22. $ThisFileInfo['zip']['uncompressed_size'] = 0;
  23. $ThisFileInfo['zip']['entries_count'] = 0;
  24. if ($ThisFileInfo['filesize'] < pow(2, 31)) {
  25. $EOCDsearchData = '';
  26. $EOCDsearchCounter = 0;
  27. while ($EOCDsearchCounter++ < 512) {
  28. fseek($fd, -128 * $EOCDsearchCounter, SEEK_END);
  29. $EOCDsearchData = fread($fd, 128).$EOCDsearchData;
  30. if (strstr($EOCDsearchData, 'PK'."\x05\x06")) {
  31. $EOCDposition = strpos($EOCDsearchData, 'PK'."\x05\x06");
  32. fseek($fd, (-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END);
  33. $ThisFileInfo['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory($fd);
  34. fseek($fd, $ThisFileInfo['zip']['end_central_directory']['directory_offset'], SEEK_SET);
  35. $ThisFileInfo['zip']['entries_count'] = 0;
  36. while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($fd)) {
  37. $ThisFileInfo['zip']['central_directory'][] = $centraldirectoryentry;
  38. $ThisFileInfo['zip']['entries_count']++;
  39. $ThisFileInfo['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
  40. $ThisFileInfo['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
  41. if ($centraldirectoryentry['uncompressed_size'] > 0) {
  42. $ThisFileInfo['zip']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['zip']['files'], getid3_lib::CreateDeepArray($centraldirectoryentry['filename'], '/', $centraldirectoryentry['uncompressed_size']));
  43. }
  44. }
  45. if ($ThisFileInfo['zip']['entries_count'] == 0) {
  46. $ThisFileInfo['error'][] = 'No Central Directory entries found (truncated file?)';
  47. return false;
  48. }
  49. if (!empty($ThisFileInfo['zip']['end_central_directory']['comment'])) {
  50. $ThisFileInfo['zip']['comments']['comment'][] = $ThisFileInfo['zip']['end_central_directory']['comment'];
  51. }
  52. if (isset($ThisFileInfo['zip']['central_directory'][0]['compression_method'])) {
  53. $ThisFileInfo['zip']['compression_method'] = $ThisFileInfo['zip']['central_directory'][0]['compression_method'];
  54. }
  55. if (isset($ThisFileInfo['zip']['central_directory'][0]['flags']['compression_speed'])) {
  56. $ThisFileInfo['zip']['compression_speed'] = $ThisFileInfo['zip']['central_directory'][0]['flags']['compression_speed'];
  57. }
  58. if (isset($ThisFileInfo['zip']['compression_method']) && ($ThisFileInfo['zip']['compression_method'] == 'store') && !isset($ThisFileInfo['zip']['compression_speed'])) {
  59. $ThisFileInfo['zip']['compression_speed'] = 'store';
  60. }
  61. return true;
  62. }
  63. }
  64. }
  65. if ($this->getZIPentriesFilepointer($fd, $ThisFileInfo)) {
  66. // central directory couldn't be found and/or parsed
  67. // scan through actual file data entries, recover as much as possible from probable trucated file
  68. if ($ThisFileInfo['zip']['compressed_size'] > ($ThisFileInfo['filesize'] - 46 - 22)) {
  69. $ThisFileInfo['error'][] = 'Warning: Truncated file! - Total compressed file sizes ('.$ThisFileInfo['zip']['compressed_size'].' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures ('.($ThisFileInfo['filesize'] - 46 - 22).' bytes)';
  70. }
  71. $ThisFileInfo['error'][] = 'Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete';
  72. foreach ($ThisFileInfo['zip']['entries'] as $key => $valuearray) {
  73. $ThisFileInfo['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size'];
  74. }
  75. return true;
  76. } else {
  77. unset($ThisFileInfo['zip']);
  78. $ThisFileInfo['fileformat'] = '';
  79. $ThisFileInfo['error'][] = 'Cannot find End Of Central Directory (truncated file?)';
  80. return false;
  81. }
  82. }
  83. function getZIPHeaderFilepointerTopDown(&$fd, &$ThisFileInfo) {
  84. $ThisFileInfo['fileformat'] = 'zip';
  85. $ThisFileInfo['zip']['compressed_size'] = 0;
  86. $ThisFileInfo['zip']['uncompressed_size'] = 0;
  87. $ThisFileInfo['zip']['entries_count'] = 0;
  88. rewind($fd);
  89. while ($fileentry = $this->ZIPparseLocalFileHeader($fd)) {
  90. $ThisFileInfo['zip']['entries'][] = $fileentry;
  91. $ThisFileInfo['zip']['entries_count']++;
  92. }
  93. if ($ThisFileInfo['zip']['entries_count'] == 0) {
  94. $ThisFileInfo['error'][] = 'No Local File Header entries found';
  95. return false;
  96. }
  97. $ThisFileInfo['zip']['entries_count'] = 0;
  98. while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($fd)) {
  99. $ThisFileInfo['zip']['central_directory'][] = $centraldirectoryentry;
  100. $ThisFileInfo['zip']['entries_count']++;
  101. $ThisFileInfo['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
  102. $ThisFileInfo['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
  103. }
  104. if ($ThisFileInfo['zip']['entries_count'] == 0) {
  105. $ThisFileInfo['error'][] = 'No Central Directory entries found (truncated file?)';
  106. return false;
  107. }
  108. if ($EOCD = $this->ZIPparseEndOfCentralDirectory($fd)) {
  109. $ThisFileInfo['zip']['end_central_directory'] = $EOCD;
  110. } else {
  111. $ThisFileInfo['error'][] = 'No End Of Central Directory entry found (truncated file?)';
  112. return false;
  113. }
  114. if (!empty($ThisFileInfo['zip']['end_central_directory']['comment'])) {
  115. $ThisFileInfo['zip']['comments']['comment'][] = $ThisFileInfo['zip']['end_central_directory']['comment'];
  116. }
  117. return true;
  118. }
  119. function getZIPentriesFilepointer(&$fd, &$ThisFileInfo) {
  120. $ThisFileInfo['zip']['compressed_size'] = 0;
  121. $ThisFileInfo['zip']['uncompressed_size'] = 0;
  122. $ThisFileInfo['zip']['entries_count'] = 0;
  123. rewind($fd);
  124. while ($fileentry = $this->ZIPparseLocalFileHeader($fd)) {
  125. $ThisFileInfo['zip']['entries'][] = $fileentry;
  126. $ThisFileInfo['zip']['entries_count']++;
  127. $ThisFileInfo['zip']['compressed_size'] += $fileentry['compressed_size'];
  128. $ThisFileInfo['zip']['uncompressed_size'] += $fileentry['uncompressed_size'];
  129. }
  130. if ($ThisFileInfo['zip']['entries_count'] == 0) {
  131. $ThisFileInfo['error'][] = 'No Local File Header entries found';
  132. return false;
  133. }
  134. return true;
  135. }
  136. function ZIPparseLocalFileHeader(&$fd) {
  137. $LocalFileHeader['offset'] = ftell($fd);
  138. $ZIPlocalFileHeader = fread($fd, 30);
  139. $LocalFileHeader['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 0, 4));
  140. if ($LocalFileHeader['raw']['signature'] != 0x04034B50) {
  141. // invalid Local File Header Signature
  142. fseek($fd, $LocalFileHeader['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
  143. return false;
  144. }
  145. $LocalFileHeader['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 4, 2));
  146. $LocalFileHeader['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 6, 2));
  147. $LocalFileHeader['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 8, 2));
  148. $LocalFileHeader['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 10, 2));
  149. $LocalFileHeader['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 12, 2));
  150. $LocalFileHeader['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 14, 4));
  151. $LocalFileHeader['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 18, 4));
  152. $LocalFileHeader['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 22, 4));
  153. $LocalFileHeader['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 26, 2));
  154. $LocalFileHeader['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 28, 2));
  155. $LocalFileHeader['extract_version'] = sprintf('%1.1f', $LocalFileHeader['raw']['extract_version'] / 10);
  156. $LocalFileHeader['host_os'] = $this->ZIPversionOSLookup(($LocalFileHeader['raw']['extract_version'] & 0xFF00) >> 8);
  157. $LocalFileHeader['compression_method'] = $this->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']);
  158. $LocalFileHeader['compressed_size'] = $LocalFileHeader['raw']['compressed_size'];
  159. $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['raw']['uncompressed_size'];
  160. $LocalFileHeader['flags'] = $this->ZIPparseGeneralPurposeFlags($LocalFileHeader['raw']['general_flags'], $LocalFileHeader['raw']['compression_method']);
  161. $LocalFileHeader['last_modified_timestamp'] = $this->DOStime2UNIXtime($LocalFileHeader['raw']['last_mod_file_date'], $LocalFileHeader['raw']['last_mod_file_time']);
  162. $FilenameExtrafieldLength = $LocalFileHeader['raw']['filename_length'] + $LocalFileHeader['raw']['extra_field_length'];
  163. if ($FilenameExtrafieldLength > 0) {
  164. $ZIPlocalFileHeader .= fread($fd, $FilenameExtrafieldLength);
  165. if ($LocalFileHeader['raw']['filename_length'] > 0) {
  166. $LocalFileHeader['filename'] = substr($ZIPlocalFileHeader, 30, $LocalFileHeader['raw']['filename_length']);
  167. }
  168. if ($LocalFileHeader['raw']['extra_field_length'] > 0) {
  169. $LocalFileHeader['raw']['extra_field_data'] = substr($ZIPlocalFileHeader, 30 + $LocalFileHeader['raw']['filename_length'], $LocalFileHeader['raw']['extra_field_length']);
  170. }
  171. }
  172. $LocalFileHeader['data_offset'] = ftell($fd);
  173. //$LocalFileHeader['compressed_data'] = fread($fd, $LocalFileHeader['raw']['compressed_size']);
  174. fseek($fd, $LocalFileHeader['raw']['compressed_size'], SEEK_CUR);
  175. if ($LocalFileHeader['flags']['data_descriptor_used']) {
  176. $DataDescriptor = fread($fd, 12);
  177. $LocalFileHeader['data_descriptor']['crc_32'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 0, 4));
  178. $LocalFileHeader['data_descriptor']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 4, 4));
  179. $LocalFileHeader['data_descriptor']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 8, 4));
  180. }
  181. return $LocalFileHeader;
  182. }
  183. function ZIPparseCentralDirectory(&$fd) {
  184. $CentralDirectory['offset'] = ftell($fd);
  185. $ZIPcentralDirectory = fread($fd, 46);
  186. $CentralDirectory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 0, 4));
  187. if ($CentralDirectory['raw']['signature'] != 0x02014B50) {
  188. // invalid Central Directory Signature
  189. fseek($fd, $CentralDirectory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
  190. return false;
  191. }
  192. $CentralDirectory['raw']['create_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 4, 2));
  193. $CentralDirectory['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 6, 2));
  194. $CentralDirectory['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 8, 2));
  195. $CentralDirectory['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 10, 2));
  196. $CentralDirectory['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 12, 2));
  197. $CentralDirectory['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 14, 2));
  198. $CentralDirectory['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 16, 4));
  199. $CentralDirectory['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 20, 4));
  200. $CentralDirectory['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 24, 4));
  201. $CentralDirectory['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 28, 2));
  202. $CentralDirectory['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 30, 2));
  203. $CentralDirectory['raw']['file_comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 32, 2));
  204. $CentralDirectory['raw']['disk_number_start'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 34, 2));
  205. $CentralDirectory['raw']['internal_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 36, 2));
  206. $CentralDirectory['raw']['external_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 38, 4));
  207. $CentralDirectory['raw']['local_header_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 42, 4));
  208. $CentralDirectory['entry_offset'] = $CentralDirectory['raw']['local_header_offset'];
  209. $CentralDirectory['create_version'] = sprintf('%1.1f', $CentralDirectory['raw']['create_version'] / 10);
  210. $CentralDirectory['extract_version'] = sprintf('%1.1f', $CentralDirectory['raw']['extract_version'] / 10);
  211. $CentralDirectory['host_os'] = $this->ZIPversionOSLookup(($CentralDirectory['raw']['extract_version'] & 0xFF00) >> 8);
  212. $CentralDirectory['compression_method'] = $this->ZIPcompressionMethodLookup($CentralDirectory['raw']['compression_method']);
  213. $CentralDirectory['compressed_size'] = $CentralDirectory['raw']['compressed_size'];
  214. $CentralDirectory['uncompressed_size'] = $CentralDirectory['raw']['uncompressed_size'];
  215. $CentralDirectory['flags'] = $this->ZIPparseGeneralPurposeFlags($CentralDirectory['raw']['general_flags'], $CentralDirectory['raw']['compression_method']);
  216. $CentralDirectory['last_modified_timestamp'] = $this->DOStime2UNIXtime($CentralDirectory['raw']['last_mod_file_date'], $CentralDirectory['raw']['last_mod_file_time']);
  217. $FilenameExtrafieldCommentLength = $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'] + $CentralDirectory['raw']['file_comment_length'];
  218. if ($FilenameExtrafieldCommentLength > 0) {
  219. $FilenameExtrafieldComment = fread($fd, $FilenameExtrafieldCommentLength);
  220. if ($CentralDirectory['raw']['filename_length'] > 0) {
  221. $CentralDirectory['filename'] = substr($FilenameExtrafieldComment, 0, $CentralDirectory['raw']['filename_length']);
  222. }
  223. if ($CentralDirectory['raw']['extra_field_length'] > 0) {
  224. $CentralDirectory['raw']['extra_field_data'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'], $CentralDirectory['raw']['extra_field_length']);
  225. }
  226. if ($CentralDirectory['raw']['file_comment_length'] > 0) {
  227. $CentralDirectory['file_comment'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'], $CentralDirectory['raw']['file_comment_length']);
  228. }
  229. }
  230. return $CentralDirectory;
  231. }
  232. function ZIPparseEndOfCentralDirectory(&$fd) {
  233. $EndOfCentralDirectory['offset'] = ftell($fd);
  234. $ZIPendOfCentralDirectory = fread($fd, 22);
  235. $EndOfCentralDirectory['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4));
  236. if ($EndOfCentralDirectory['signature'] != 0x06054B50) {
  237. // invalid End Of Central Directory Signature
  238. fseek($fd, $EndOfCentralDirectory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
  239. return false;
  240. }
  241. $EndOfCentralDirectory['disk_number_current'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 4, 2));
  242. $EndOfCentralDirectory['disk_number_start_directory'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 6, 2));
  243. $EndOfCentralDirectory['directory_entries_this_disk'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 8, 2));
  244. $EndOfCentralDirectory['directory_entries_total'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 10, 2));
  245. $EndOfCentralDirectory['directory_size'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 12, 4));
  246. $EndOfCentralDirectory['directory_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 16, 4));
  247. $EndOfCentralDirectory['comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 20, 2));
  248. if ($EndOfCentralDirectory['comment_length'] > 0) {
  249. $EndOfCentralDirectory['comment'] = fread($fd, $EndOfCentralDirectory['comment_length']);
  250. }
  251. return $EndOfCentralDirectory;
  252. }
  253. function ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod) {
  254. $ParsedFlags['encrypted'] = (bool) ($flagbytes & 0x0001);
  255. switch ($compressionmethod) {
  256. case 6:
  257. $ParsedFlags['dictionary_size'] = (($flagbytes & 0x0002) ? 8192 : 4096);
  258. $ParsedFlags['shannon_fano_trees'] = (($flagbytes & 0x0004) ? 3 : 2);
  259. break;
  260. case 8:
  261. case 9:
  262. switch (($flagbytes & 0x0006) >> 1) {
  263. case 0:
  264. $ParsedFlags['compression_speed'] = 'normal';
  265. break;
  266. case 1:
  267. $ParsedFlags['compression_speed'] = 'maximum';
  268. break;
  269. case 2:
  270. $ParsedFlags['compression_speed'] = 'fast';
  271. break;
  272. case 3:
  273. $ParsedFlags['compression_speed'] = 'superfast';
  274. break;
  275. }
  276. break;
  277. }
  278. $ParsedFlags['data_descriptor_used'] = (bool) ($flagbytes & 0x0008);
  279. return $ParsedFlags;
  280. }
  281. function ZIPversionOSLookup($index) {
  282. static $ZIPversionOSLookup = array(
  283. 0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)',
  284. 1 => 'Amiga',
  285. 2 => 'OpenVMS',
  286. 3 => 'Unix',
  287. 4 => 'VM/CMS',
  288. 5 => 'Atari ST',
  289. 6 => 'OS/2 H.P.F.S.',
  290. 7 => 'Macintosh',
  291. 8 => 'Z-System',
  292. 9 => 'CP/M',
  293. 10 => 'Windows NTFS',
  294. 11 => 'MVS',
  295. 12 => 'VSE',
  296. 13 => 'Acorn Risc',
  297. 14 => 'VFAT',
  298. 15 => 'Alternate MVS',
  299. 16 => 'BeOS',
  300. 17 => 'Tandem'
  301. );
  302. return (isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] : '[unknown]');
  303. }
  304. function ZIPcompressionMethodLookup($index) {
  305. static $ZIPcompressionMethodLookup = array(
  306. 0 => 'store',
  307. 1 => 'shrink',
  308. 2 => 'reduce-1',
  309. 3 => 'reduce-2',
  310. 4 => 'reduce-3',
  311. 5 => 'reduce-4',
  312. 6 => 'implode',
  313. 7 => 'tokenize',
  314. 8 => 'deflate',
  315. 9 => 'deflate64',
  316. 10 => 'PKWARE Date Compression Library Imploding'
  317. );
  318. return (isset($ZIPcompressionMethodLookup[$index]) ? $ZIPcompressionMethodLookup[$index] : '[unknown]');
  319. }
  320. function DOStime2UNIXtime($DOSdate, $DOStime) {
  321. // wFatDate
  322. // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format:
  323. // Bits Contents
  324. // 0-4 Day of the month (1-31)
  325. // 5-8 Month (1 = January, 2 = February, and so on)
  326. // 9-15 Year offset from 1980 (add 1980 to get actual year)
  327. $UNIXday = ($DOSdate & 0x001F);
  328. $UNIXmonth = (($DOSdate & 0x01E0) >> 5);
  329. $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980;
  330. // wFatTime
  331. // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format:
  332. // Bits Contents
  333. // 0-4 Second divided by 2
  334. // 5-10 Minute (0-59)
  335. // 11-15 Hour (0-23 on a 24-hour clock)
  336. $UNIXsecond = ($DOStime & 0x001F) * 2;
  337. $UNIXminute = (($DOStime & 0x07E0) >> 5);
  338. $UNIXhour = (($DOStime & 0xF800) >> 11);
  339. return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear);
  340. }
  341. }
  342. ?>