module.archive.zip.php 20 KB

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