PageRenderTime 63ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/vtlib/thirdparty/dUnzip2.inc.php

https://bitbucket.org/thomashii/vtigercrm-6-for-postgresql
PHP | 517 lines | 403 code | 37 blank | 77 comment | 57 complexity | caf8311e0cc5b0b04cc1de6cf2c9e136 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.1, GPL-2.0, GPL-3.0
  1. <?php
  2. /**
  3. * DOWNLOADED FROM: http://www.phpclasses.org/browse/package/2495/
  4. * License: BSD License
  5. */
  6. ?>
  7. <?php
  8. // 15/07/2006 (2.6)
  9. // - Changed the algorithm to parse the ZIP file.. Now, the script will try to mount the compressed
  10. // list, searching on the 'Central Dir' records. If it fails, the script will try to search by
  11. // checking every signature. Thanks to Jayson Cruz for pointing it.
  12. // 25/01/2006 (2.51)
  13. // - Fixed bug when calling 'unzip' without calling 'getList' first. Thanks to Bala Murthu for pointing it.
  14. // 01/12/2006 (2.5)
  15. // - Added optional parameter "applyChmod" for the "unzip()" method. It auto applies the given chmod for
  16. // extracted files.
  17. // - Permission 777 (all read-write-exec) is default. If you want to change it, you'll need to make it
  18. // explicit. (If you want the OS to determine, set "false" as "applyChmod" parameter)
  19. // 28/11/2005 (2.4)
  20. // - dUnzip2 is now compliant with old-style "Data Description", made by some compressors,
  21. // like the classes ZipLib and ZipLib2 by 'Hasin Hayder'. Thanks to Ricardo Parreno for pointing it.
  22. // 09/11/2005 (2.3)
  23. // - Added optional parameter '$stopOnFile' on method 'getList()'.
  24. // If given, file listing will stop when find given filename. (Useful to open and unzip an exact file)
  25. // 06/11/2005 (2.21)
  26. // - Added support to PK00 file format (Packed to Removable Disk) (thanks to Lito [PHPfileNavigator])
  27. // - Method 'getExtraInfo': If requested file doesn't exist, return FALSE instead of Array()
  28. // 31/10/2005 (2.2)
  29. // - Removed redundant 'file_name' on centralDirs declaration (thanks to Lito [PHPfileNavigator])
  30. // - Fixed redeclaration of file_put_contents when in PHP4 (not returning true)
  31. ##############################################################
  32. # Class dUnzip2 v2.6
  33. #
  34. # Author: Alexandre Tedeschi (d)
  35. # E-Mail: alexandrebr at gmail dot com
  36. # Londrina - PR / Brazil
  37. #
  38. # Objective:
  39. # This class allows programmer to easily unzip files on the fly.
  40. #
  41. # Requirements:
  42. # This class requires extension ZLib Enabled. It is default
  43. # for most site hosts around the world, and for the PHP Win32 dist.
  44. #
  45. # To do:
  46. # * Error handling
  47. # * Write a PHP-Side gzinflate, to completely avoid any external extensions
  48. # * Write other decompress algorithms
  49. #
  50. # If you modify this class, or have any ideas to improve it, please contact me!
  51. # You are allowed to redistribute this class, if you keep my name and contact e-mail on it.
  52. #
  53. # PLEASE! IF YOU USE THIS CLASS IN ANY OF YOUR PROJECTS, PLEASE LET ME KNOW!
  54. # If you have problems using it, don't think twice before contacting me!
  55. #
  56. ##############################################################
  57. if(!function_exists('file_put_contents')){
  58. // If not PHP5, creates a compatible function
  59. Function file_put_contents($file, $data){
  60. if($tmp = fopen($file, "w")){
  61. fwrite($tmp, $data);
  62. fclose($tmp);
  63. return true;
  64. }
  65. echo "<b>file_put_contents:</b> Cannot create file $file<br>";
  66. return false;
  67. }
  68. }
  69. class dUnzip2{
  70. Function getVersion(){
  71. return "2.6";
  72. }
  73. // Public
  74. var $fileName;
  75. var $compressedList; // You will problably use only this one!
  76. var $centralDirList; // Central dir list... It's a kind of 'extra attributes' for a set of files
  77. var $endOfCentral; // End of central dir, contains ZIP Comments
  78. var $debug;
  79. // Private
  80. var $fh;
  81. var $zipSignature = "\x50\x4b\x03\x04"; // local file header signature
  82. var $dirSignature = "\x50\x4b\x01\x02"; // central dir header signature
  83. var $dirSignatureE= "\x50\x4b\x05\x06"; // end of central dir signature
  84. // Public
  85. Function dUnzip2($fileName){
  86. $this->fileName = $fileName;
  87. $this->compressedList =
  88. $this->centralDirList =
  89. $this->endOfCentral = Array();
  90. }
  91. Function getList($stopOnFile=false){
  92. if(sizeof($this->compressedList)){
  93. $this->debugMsg(1, "Returning already loaded file list.");
  94. return $this->compressedList;
  95. }
  96. // Open file, and set file handler
  97. $fh = fopen($this->fileName, "r");
  98. $this->fh = &$fh;
  99. if(!$fh){
  100. $this->debugMsg(2, "Failed to load file.");
  101. return false;
  102. }
  103. $this->debugMsg(1, "Loading list from 'End of Central Dir' index list...");
  104. if(!$this->_loadFileListByEOF($fh, $stopOnFile)){
  105. $this->debugMsg(1, "Failed! Trying to load list looking for signatures...");
  106. if(!$this->_loadFileListBySignatures($fh, $stopOnFile)){
  107. $this->debugMsg(1, "Failed! Could not find any valid header.");
  108. $this->debugMsg(2, "ZIP File is corrupted or empty");
  109. return false;
  110. }
  111. }
  112. if($this->debug){
  113. #------- Debug compressedList
  114. $kkk = 0;
  115. echo "<table border='0' style='font: 11px Verdana; border: 1px solid #000'>";
  116. foreach($this->compressedList as $fileName=>$item){
  117. if(!$kkk && $kkk=1){
  118. echo "<tr style='background: #ADA'>";
  119. foreach($item as $fieldName=>$value)
  120. echo "<td>$fieldName</td>";
  121. echo '</tr>';
  122. }
  123. echo "<tr style='background: #CFC'>";
  124. foreach($item as $fieldName=>$value){
  125. if($fieldName == 'lastmod_datetime')
  126. echo "<td title='$fieldName' nowrap='nowrap'>".date("d/m/Y H:i:s", $value)."</td>";
  127. else
  128. echo "<td title='$fieldName' nowrap='nowrap'>$value</td>";
  129. }
  130. echo "</tr>";
  131. }
  132. echo "</table>";
  133. #------- Debug centralDirList
  134. $kkk = 0;
  135. if(sizeof($this->centralDirList)){
  136. echo "<table border='0' style='font: 11px Verdana; border: 1px solid #000'>";
  137. foreach($this->centralDirList as $fileName=>$item){
  138. if(!$kkk && $kkk=1){
  139. echo "<tr style='background: #AAD'>";
  140. foreach($item as $fieldName=>$value)
  141. echo "<td>$fieldName</td>";
  142. echo '</tr>';
  143. }
  144. echo "<tr style='background: #CCF'>";
  145. foreach($item as $fieldName=>$value){
  146. if($fieldName == 'lastmod_datetime')
  147. echo "<td title='$fieldName' nowrap='nowrap'>".date("d/m/Y H:i:s", $value)."</td>";
  148. else
  149. echo "<td title='$fieldName' nowrap='nowrap'>$value</td>";
  150. }
  151. echo "</tr>";
  152. }
  153. echo "</table>";
  154. }
  155. #------- Debug endOfCentral
  156. $kkk = 0;
  157. if(sizeof($this->endOfCentral)){
  158. echo "<table border='0' style='font: 11px Verdana' style='border: 1px solid #000'>";
  159. echo "<tr style='background: #DAA'><td colspan='2'>dUnzip - End of file</td></tr>";
  160. foreach($this->endOfCentral as $field=>$value){
  161. echo "<tr>";
  162. echo "<td style='background: #FCC'>$field</td>";
  163. echo "<td style='background: #FDD'>$value</td>";
  164. echo "</tr>";
  165. }
  166. echo "</table>";
  167. }
  168. }
  169. return $this->compressedList;
  170. }
  171. Function getExtraInfo($compressedFileName){
  172. return
  173. isset($this->centralDirList[$compressedFileName])?
  174. $this->centralDirList[$compressedFileName]:
  175. false;
  176. }
  177. Function getZipInfo($detail=false){
  178. return $detail?
  179. $this->endOfCentral[$detail]:
  180. $this->endOfCentral;
  181. }
  182. Function unzip($compressedFileName, $targetFileName=false, $applyChmod=0777){
  183. if(!sizeof($this->compressedList)){
  184. $this->debugMsg(1, "Trying to unzip before loading file list... Loading it!");
  185. $this->getList(false, $compressedFileName);
  186. }
  187. $fdetails = &$this->compressedList[$compressedFileName];
  188. if(!isset($this->compressedList[$compressedFileName])){
  189. $this->debugMsg(2, "File '<b>$compressedFileName</b>' is not compressed in the zip.");
  190. return false;
  191. }
  192. if(substr($compressedFileName, -1) == "/"){
  193. $this->debugMsg(2, "Trying to unzip a folder name '<b>$compressedFileName</b>'.");
  194. return false;
  195. }
  196. if(!$fdetails['uncompressed_size']){
  197. $this->debugMsg(1, "File '<b>$compressedFileName</b>' is empty.");
  198. return $targetFileName?
  199. file_put_contents($targetFileName, ""):
  200. "";
  201. }
  202. fseek($this->fh, $fdetails['contents-startOffset']);
  203. $ret = $this->uncompress(
  204. fread($this->fh, $fdetails['compressed_size']),
  205. $fdetails['compression_method'],
  206. $fdetails['uncompressed_size'],
  207. $targetFileName
  208. );
  209. if($applyChmod && $targetFileName)
  210. @chmod($targetFileName, 0777);
  211. return $ret;
  212. }
  213. Function unzipAll($targetDir=false, $baseDir="", $maintainStructure=true, $applyChmod=0777){
  214. if($targetDir === false)
  215. $targetDir = dirname(__FILE__)."/";
  216. $lista = $this->getList();
  217. if(sizeof($lista)) foreach($lista as $fileName=>$trash){
  218. $dirname = dirname($fileName);
  219. $outDN = "$targetDir/$dirname";
  220. if(substr($dirname, 0, strlen($baseDir)) != $baseDir)
  221. continue;
  222. if(!is_dir($outDN) && $maintainStructure){
  223. $str = "";
  224. $folders = explode("/", $dirname);
  225. foreach($folders as $folder){
  226. $str = $str?"$str/$folder":$folder;
  227. if(!is_dir("$targetDir/$str")){
  228. $this->debugMsg(1, "Creating folder: $targetDir/$str");
  229. mkdir("$targetDir/$str");
  230. if($applyChmod)
  231. chmod("$targetDir/$str", $applyChmod);
  232. }
  233. }
  234. }
  235. if(substr($fileName, -1, 1) == "/")
  236. continue;
  237. $maintainStructure?
  238. $this->unzip($fileName, "$targetDir/$fileName", $applyChmod):
  239. $this->unzip($fileName, "$targetDir/".basename($fileName), $applyChmod);
  240. }
  241. }
  242. Function close(){ // Free the file resource
  243. if($this->fh)
  244. fclose($this->fh);
  245. }
  246. Function __destroy(){
  247. $this->close();
  248. }
  249. // Private (you should NOT call these methods):
  250. Function uncompress($content, $mode, $uncompressedSize, $targetFileName=false){
  251. switch($mode){
  252. case 0:
  253. // Not compressed
  254. return $targetFileName?
  255. file_put_contents($targetFileName, $content):
  256. $content;
  257. case 1:
  258. $this->debugMsg(2, "Shrunk mode is not supported... yet?");
  259. return false;
  260. case 2:
  261. case 3:
  262. case 4:
  263. case 5:
  264. $this->debugMsg(2, "Compression factor ".($mode-1)." is not supported... yet?");
  265. return false;
  266. case 6:
  267. $this->debugMsg(2, "Implode is not supported... yet?");
  268. return false;
  269. case 7:
  270. $this->debugMsg(2, "Tokenizing compression algorithm is not supported... yet?");
  271. return false;
  272. case 8:
  273. // Deflate
  274. return $targetFileName?
  275. file_put_contents($targetFileName, gzinflate($content, $uncompressedSize)):
  276. gzinflate($content, $uncompressedSize);
  277. case 9:
  278. $this->debugMsg(2, "Enhanced Deflating is not supported... yet?");
  279. return false;
  280. case 10:
  281. $this->debugMsg(2, "PKWARE Date Compression Library Impoloding is not supported... yet?");
  282. return false;
  283. case 12:
  284. // Bzip2
  285. return $targetFileName?
  286. file_put_contents($targetFileName, bzdecompress($content)):
  287. bzdecompress($content);
  288. case 18:
  289. $this->debugMsg(2, "IBM TERSE is not supported... yet?");
  290. return false;
  291. default:
  292. $this->debugMsg(2, "Unknown uncompress method: $mode");
  293. return false;
  294. }
  295. }
  296. Function debugMsg($level, $string){
  297. if($this->debug)
  298. if($level == 1)
  299. echo "<b style='color: #777'>dUnzip2:</b> $string<br>";
  300. if($level == 2)
  301. echo "<b style='color: #F00'>dUnzip2:</b> $string<br>";
  302. }
  303. Function _loadFileListByEOF(&$fh, $stopOnFile=false){
  304. // Check if there's a valid Central Dir signature.
  305. // Let's consider a file comment smaller than 1024 characters...
  306. // Actually, it length can be 65536.. But we're not going to support it.
  307. for($x = 0; $x < 1024; $x++){
  308. fseek($fh, -22-$x, SEEK_END);
  309. $signature = fread($fh, 4);
  310. if($signature == $this->dirSignatureE){
  311. // If found EOF Central Dir
  312. $eodir['disk_number_this'] = unpack("v", fread($fh, 2)); // number of this disk
  313. $eodir['disk_number'] = unpack("v", fread($fh, 2)); // number of the disk with the start of the central directory
  314. $eodir['total_entries_this'] = unpack("v", fread($fh, 2)); // total number of entries in the central dir on this disk
  315. $eodir['total_entries'] = unpack("v", fread($fh, 2)); // total number of entries in
  316. $eodir['size_of_cd'] = unpack("V", fread($fh, 4)); // size of the central directory
  317. $eodir['offset_start_cd'] = unpack("V", fread($fh, 4)); // offset of start of central directory with respect to the starting disk number
  318. $zipFileCommentLenght = unpack("v", fread($fh, 2)); // zipfile comment length
  319. $eodir['zipfile_comment'] = $zipFileCommentLenght[1]?fread($fh, $zipFileCommentLenght[1]):''; // zipfile comment
  320. $this->endOfCentral = Array(
  321. 'disk_number_this'=>$eodir['disk_number_this'][1],
  322. 'disk_number'=>$eodir['disk_number'][1],
  323. 'total_entries_this'=>$eodir['total_entries_this'][1],
  324. 'total_entries'=>$eodir['total_entries'][1],
  325. 'size_of_cd'=>$eodir['size_of_cd'][1],
  326. 'offset_start_cd'=>$eodir['offset_start_cd'][1],
  327. 'zipfile_comment'=>$eodir['zipfile_comment'],
  328. );
  329. // Then, load file list
  330. fseek($fh, $this->endOfCentral['offset_start_cd']);
  331. $signature = fread($fh, 4);
  332. while($signature == $this->dirSignature){
  333. $dir['version_madeby'] = unpack("v", fread($fh, 2)); // version made by
  334. $dir['version_needed'] = unpack("v", fread($fh, 2)); // version needed to extract
  335. $dir['general_bit_flag'] = unpack("v", fread($fh, 2)); // general purpose bit flag
  336. $dir['compression_method'] = unpack("v", fread($fh, 2)); // compression method
  337. $dir['lastmod_time'] = unpack("v", fread($fh, 2)); // last mod file time
  338. $dir['lastmod_date'] = unpack("v", fread($fh, 2)); // last mod file date
  339. $dir['crc-32'] = fread($fh, 4); // crc-32
  340. $dir['compressed_size'] = unpack("V", fread($fh, 4)); // compressed size
  341. $dir['uncompressed_size'] = unpack("V", fread($fh, 4)); // uncompressed size
  342. $fileNameLength = unpack("v", fread($fh, 2)); // filename length
  343. $extraFieldLength = unpack("v", fread($fh, 2)); // extra field length
  344. $fileCommentLength = unpack("v", fread($fh, 2)); // file comment length
  345. $dir['disk_number_start'] = unpack("v", fread($fh, 2)); // disk number start
  346. $dir['internal_attributes'] = unpack("v", fread($fh, 2)); // internal file attributes-byte1
  347. $dir['external_attributes1']= unpack("v", fread($fh, 2)); // external file attributes-byte2
  348. $dir['external_attributes2']= unpack("v", fread($fh, 2)); // external file attributes
  349. $dir['relative_offset'] = unpack("V", fread($fh, 4)); // relative offset of local header
  350. $dir['file_name'] = fread($fh, $fileNameLength[1]); // filename
  351. $dir['extra_field'] = $extraFieldLength[1] ?fread($fh, $extraFieldLength[1]) :''; // extra field
  352. $dir['file_comment'] = $fileCommentLength[1]?fread($fh, $fileCommentLength[1]):''; // file comment
  353. // Convert the date and time, from MS-DOS format to UNIX Timestamp
  354. $BINlastmod_date = str_pad(decbin($dir['lastmod_date'][1]), 16, '0', STR_PAD_LEFT);
  355. $BINlastmod_time = str_pad(decbin($dir['lastmod_time'][1]), 16, '0', STR_PAD_LEFT);
  356. $lastmod_dateY = bindec(substr($BINlastmod_date, 0, 7))+1980;
  357. $lastmod_dateM = bindec(substr($BINlastmod_date, 7, 4));
  358. $lastmod_dateD = bindec(substr($BINlastmod_date, 11, 5));
  359. $lastmod_timeH = bindec(substr($BINlastmod_time, 0, 5));
  360. $lastmod_timeM = bindec(substr($BINlastmod_time, 5, 6));
  361. $lastmod_timeS = bindec(substr($BINlastmod_time, 11, 5));
  362. $this->centralDirList[$dir['file_name']] = Array(
  363. 'version_madeby'=>$dir['version_madeby'][1],
  364. 'version_needed'=>$dir['version_needed'][1],
  365. 'general_bit_flag'=>str_pad(decbin($dir['general_bit_flag'][1]), 8, '0', STR_PAD_LEFT),
  366. 'compression_method'=>$dir['compression_method'][1],
  367. 'lastmod_datetime' =>mktime($lastmod_timeH, $lastmod_timeM, $lastmod_timeS, $lastmod_dateM, $lastmod_dateD, $lastmod_dateY),
  368. 'crc-32' =>str_pad(dechex(ord($dir['crc-32'][3])), 2, '0', STR_PAD_LEFT).
  369. str_pad(dechex(ord($dir['crc-32'][2])), 2, '0', STR_PAD_LEFT).
  370. str_pad(dechex(ord($dir['crc-32'][1])), 2, '0', STR_PAD_LEFT).
  371. str_pad(dechex(ord($dir['crc-32'][0])), 2, '0', STR_PAD_LEFT),
  372. 'compressed_size'=>$dir['compressed_size'][1],
  373. 'uncompressed_size'=>$dir['uncompressed_size'][1],
  374. 'disk_number_start'=>$dir['disk_number_start'][1],
  375. 'internal_attributes'=>$dir['internal_attributes'][1],
  376. 'external_attributes1'=>$dir['external_attributes1'][1],
  377. 'external_attributes2'=>$dir['external_attributes2'][1],
  378. 'relative_offset'=>$dir['relative_offset'][1],
  379. 'file_name'=>$dir['file_name'],
  380. 'extra_field'=>$dir['extra_field'],
  381. 'file_comment'=>$dir['file_comment'],
  382. );
  383. $signature = fread($fh, 4);
  384. }
  385. // If loaded centralDirs, then try to identify the offsetPosition of the compressed data.
  386. if($this->centralDirList) foreach($this->centralDirList as $filename=>$details){
  387. $i = $this->_getFileHeaderInformation($fh, $details['relative_offset']);
  388. $this->compressedList[$filename]['file_name'] = $filename;
  389. $this->compressedList[$filename]['compression_method'] = $details['compression_method'];
  390. $this->compressedList[$filename]['version_needed'] = $details['version_needed'];
  391. $this->compressedList[$filename]['lastmod_datetime'] = $details['lastmod_datetime'];
  392. $this->compressedList[$filename]['crc-32'] = $details['crc-32'];
  393. $this->compressedList[$filename]['compressed_size'] = $details['compressed_size'];
  394. $this->compressedList[$filename]['uncompressed_size'] = $details['uncompressed_size'];
  395. $this->compressedList[$filename]['lastmod_datetime'] = $details['lastmod_datetime'];
  396. $this->compressedList[$filename]['extra_field'] = $i['extra_field'];
  397. $this->compressedList[$filename]['contents-startOffset']=$i['contents-startOffset'];
  398. if(strtolower($stopOnFile) == strtolower($filename))
  399. break;
  400. }
  401. return true;
  402. }
  403. }
  404. return false;
  405. }
  406. Function _loadFileListBySignatures(&$fh, $stopOnFile=false){
  407. fseek($fh, 0);
  408. $return = false;
  409. for(;;){
  410. $details = $this->_getFileHeaderInformation($fh);
  411. if(!$details){
  412. $this->debugMsg(1, "Invalid signature. Trying to verify if is old style Data Descriptor...");
  413. fseek($fh, 12 - 4, SEEK_CUR); // 12: Data descriptor - 4: Signature (that will be read again)
  414. $details = $this->_getFileHeaderInformation($fh);
  415. }
  416. if(!$details){
  417. $this->debugMsg(1, "Still invalid signature. Probably reached the end of the file.");
  418. break;
  419. }
  420. $filename = $details['file_name'];
  421. $this->compressedList[$filename] = $details;
  422. $return = true;
  423. if(strtolower($stopOnFile) == strtolower($filename))
  424. break;
  425. }
  426. return $return;
  427. }
  428. Function _getFileHeaderInformation(&$fh, $startOffset=false){
  429. if($startOffset !== false)
  430. fseek($fh, $startOffset);
  431. $signature = fread($fh, 4);
  432. if($signature == $this->zipSignature){
  433. # $this->debugMsg(1, "Zip Signature!");
  434. // Get information about the zipped file
  435. $file['version_needed'] = unpack("v", fread($fh, 2)); // version needed to extract
  436. $file['general_bit_flag'] = unpack("v", fread($fh, 2)); // general purpose bit flag
  437. $file['compression_method'] = unpack("v", fread($fh, 2)); // compression method
  438. $file['lastmod_time'] = unpack("v", fread($fh, 2)); // last mod file time
  439. $file['lastmod_date'] = unpack("v", fread($fh, 2)); // last mod file date
  440. $file['crc-32'] = fread($fh, 4); // crc-32
  441. $file['compressed_size'] = unpack("V", fread($fh, 4)); // compressed size
  442. $file['uncompressed_size'] = unpack("V", fread($fh, 4)); // uncompressed size
  443. $fileNameLength = unpack("v", fread($fh, 2)); // filename length
  444. $extraFieldLength = unpack("v", fread($fh, 2)); // extra field length
  445. $file['file_name'] = fread($fh, $fileNameLength[1]); // filename
  446. $file['extra_field'] = $extraFieldLength[1]?fread($fh, $extraFieldLength[1]):''; // extra field
  447. $file['contents-startOffset']= ftell($fh);
  448. // Bypass the whole compressed contents, and look for the next file
  449. fseek($fh, $file['compressed_size'][1], SEEK_CUR);
  450. // Convert the date and time, from MS-DOS format to UNIX Timestamp
  451. $BINlastmod_date = str_pad(decbin($file['lastmod_date'][1]), 16, '0', STR_PAD_LEFT);
  452. $BINlastmod_time = str_pad(decbin($file['lastmod_time'][1]), 16, '0', STR_PAD_LEFT);
  453. $lastmod_dateY = bindec(substr($BINlastmod_date, 0, 7))+1980;
  454. $lastmod_dateM = bindec(substr($BINlastmod_date, 7, 4));
  455. $lastmod_dateD = bindec(substr($BINlastmod_date, 11, 5));
  456. $lastmod_timeH = bindec(substr($BINlastmod_time, 0, 5));
  457. $lastmod_timeM = bindec(substr($BINlastmod_time, 5, 6));
  458. $lastmod_timeS = bindec(substr($BINlastmod_time, 11, 5));
  459. // Mount file table
  460. $i = Array(
  461. 'file_name' =>$file['file_name'],
  462. 'compression_method'=>$file['compression_method'][1],
  463. 'version_needed' =>$file['version_needed'][1],
  464. 'lastmod_datetime' =>mktime($lastmod_timeH, $lastmod_timeM, $lastmod_timeS, $lastmod_dateM, $lastmod_dateD, $lastmod_dateY),
  465. 'crc-32' =>str_pad(dechex(ord($file['crc-32'][3])), 2, '0', STR_PAD_LEFT).
  466. str_pad(dechex(ord($file['crc-32'][2])), 2, '0', STR_PAD_LEFT).
  467. str_pad(dechex(ord($file['crc-32'][1])), 2, '0', STR_PAD_LEFT).
  468. str_pad(dechex(ord($file['crc-32'][0])), 2, '0', STR_PAD_LEFT),
  469. 'compressed_size' =>$file['compressed_size'][1],
  470. 'uncompressed_size' =>$file['uncompressed_size'][1],
  471. 'extra_field' =>$file['extra_field'],
  472. 'general_bit_flag' =>str_pad(decbin($file['general_bit_flag'][1]), 8, '0', STR_PAD_LEFT),
  473. 'contents-startOffset'=>$file['contents-startOffset']
  474. );
  475. return $i;
  476. }
  477. return false;
  478. }
  479. }
  480. ?>