unzip.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <?php
  2. /**
  3. * Part of the Fuel framework.
  4. *
  5. * @package Fuel
  6. * @version 1.5
  7. * @author Fuel Development Team
  8. * @license MIT License
  9. * @copyright 2010 - 2013 Fuel Development Team
  10. * @link http://fuelphp.com
  11. */
  12. namespace Fuel\Core;
  13. /**
  14. * UnZip Class
  15. *
  16. * This class is based on a library I found at PHPClasses:
  17. * http://phpclasses.org/package/2495-PHP-Pack-and-unpack-files-packed-in-ZIP-archives.html
  18. *
  19. * The original library is a little rough around the edges so I
  20. * refactored it and added several additional methods -- Phil Sturgeon
  21. *
  22. * This class requires extension ZLib Enabled.
  23. *
  24. * @package Fuel
  25. * @subpackage Core
  26. * @category Encryption
  27. * @author Alexandre Tedeschi
  28. * @author Phil Sturgeon
  29. * @license
  30. * @version 1.0.0
  31. */
  32. class Unzip
  33. {
  34. private $compressed_list = array();
  35. // List of files in the ZIP
  36. private $central_dir_list = array();
  37. // Central dir list... It's a kind of 'extra attributes' for a set of files
  38. private $end_of_central = array();
  39. // End of central dir, contains ZIP Comments
  40. private $info = array();
  41. private $error = array();
  42. private $_zip_file = '';
  43. private $_target_dir = false;
  44. private $apply_chmod = 0777;
  45. private $fh;
  46. private $zip_signature = "\x50\x4b\x03\x04";
  47. // local file header signature
  48. private $dir_signature = "\x50\x4b\x01\x02";
  49. // central dir header signature
  50. private $central_signature_end = "\x50\x4b\x05\x06";
  51. // ignore these directories (useless meta data)
  52. private $_skip_dirs = array('__MACOSX');
  53. private $_allow_extensions = NULL; // What is allowed out of the zip
  54. // --------------------------------------------------------------------
  55. /**
  56. * Unzip all files in archive.
  57. *
  58. * @access Public
  59. * @param none
  60. * @return none
  61. */
  62. public function extract($zip_file, $target_dir = NULL, $preserve_filepath = TRUE)
  63. {
  64. $this->_zip_file = $zip_file;
  65. $this->_target_dir = $target_dir ? $target_dir : dirname($this->_zip_file);
  66. if ( ! $files = $this->_list_files())
  67. {
  68. throw new \FuelException('ZIP folder was empty.');
  69. return false;
  70. }
  71. $file_locations = array();
  72. foreach ($files as $file => $trash)
  73. {
  74. $dirname = pathinfo($file, PATHINFO_DIRNAME);
  75. $extension = pathinfo($file, PATHINFO_EXTENSION);
  76. $folders = explode('/', $dirname);
  77. $out_dn = $this->_target_dir . '/' . $dirname;
  78. // Skip stuff in stupid folders
  79. if (in_array(current($folders), $this->_skip_dirs))
  80. {
  81. continue;
  82. }
  83. // Skip any files that are not allowed
  84. if (is_array($this->_allow_extensions) AND $extension AND ! in_array($extension, $this->_allow_extensions))
  85. {
  86. continue;
  87. }
  88. if ( ! is_dir($out_dn) AND $preserve_filepath)
  89. {
  90. $str = "";
  91. foreach ($folders as $folder)
  92. {
  93. $str = $str ? $str . '/' . $folder : $folder;
  94. if ( ! is_dir($this->_target_dir . '/' . $str))
  95. {
  96. $this->set_debug('Creating folder: ' . $this->_target_dir . '/' . $str);
  97. if ( ! @mkdir($this->_target_dir . '/' . $str))
  98. {
  99. throw new \FuelException('Desitnation path is not writable.');
  100. return false;
  101. }
  102. // Apply chmod if configured to do so
  103. $this->apply_chmod AND chmod($this->_target_dir . '/' . $str, $this->apply_chmod);
  104. }
  105. }
  106. }
  107. if (substr($file, -1, 1) == '/') continue;
  108. $file_locations[] = $file_location = $this->_target_dir . '/' . ($preserve_filepath ? $file : basename($file));
  109. $this->_extract_file($file, $file_location);
  110. }
  111. return $file_locations;
  112. }
  113. // --------------------------------------------------------------------
  114. /**
  115. * What extensions do we want out of this ZIP
  116. *
  117. * @access Public
  118. * @param none
  119. * @return none
  120. */
  121. public function allow($ext = NULL)
  122. {
  123. $this->_allow_extensions = $ext;
  124. }
  125. // --------------------------------------------------------------------
  126. /**
  127. * Show error messages
  128. *
  129. * @access public
  130. * @param string
  131. * @return string
  132. */
  133. public function error_string($open = '<p>', $close = '</p>')
  134. {
  135. return $open . implode($close . $open, $this->error) . $close;
  136. }
  137. // --------------------------------------------------------------------
  138. /**
  139. * Show debug messages
  140. *
  141. * @access public
  142. * @param string
  143. * @return string
  144. */
  145. public function debug_string($open = '<p>', $close = '</p>')
  146. {
  147. return $open . implode($close . $open, $this->info) . $close;
  148. }
  149. // --------------------------------------------------------------------
  150. /**
  151. * Save errors
  152. *
  153. * @access Private
  154. * @param string
  155. * @return none
  156. */
  157. function set_error($string)
  158. {
  159. $this->error[] = $string;
  160. }
  161. // --------------------------------------------------------------------
  162. /**
  163. * Save debug data
  164. *
  165. * @access Private
  166. * @param string
  167. * @return none
  168. */
  169. function set_debug($string)
  170. {
  171. $this->info[] = $string;
  172. }
  173. // --------------------------------------------------------------------
  174. /**
  175. * List all files in archive.
  176. *
  177. * @access Public
  178. * @param boolean
  179. * @return mixed
  180. */
  181. private function _list_files($stop_on_file = false)
  182. {
  183. if (sizeof($this->compressed_list))
  184. {
  185. $this->set_debug('Returning already loaded file list.');
  186. return $this->compressed_list;
  187. }
  188. // Open file, and set file handler
  189. $fh = fopen($this->_zip_file, 'r');
  190. $this->fh = &$fh;
  191. if ( ! $fh)
  192. {
  193. throw new \FuelException('Failed to load file: ' . $this->_zip_file);
  194. return false;
  195. }
  196. $this->set_debug('Loading list from "End of Central Dir" index list...');
  197. if ( ! $this->_load_file_list_by_eof($fh, $stop_on_file))
  198. {
  199. $this->set_debug('Failed! Trying to load list looking for signatures...');
  200. if ( ! $this->_load_files_by_signatures($fh, $stop_on_file))
  201. {
  202. $this->set_debug('Failed! Could not find any valid header.');
  203. throw new \FuelException('ZIP File is corrupted or empty');
  204. return false;
  205. }
  206. }
  207. return $this->compressed_list;
  208. }
  209. // --------------------------------------------------------------------
  210. /**
  211. * Unzip file in archive.
  212. *
  213. * @access Public
  214. * @param string, boolean
  215. * @return Unziped file.
  216. */
  217. private function _extract_file($compressed_file_name, $target_file_name = false)
  218. {
  219. if ( ! sizeof($this->compressed_list))
  220. {
  221. $this->set_debug('Trying to unzip before loading file list... Loading it!');
  222. $this->_list_files(false, $compressed_file_name);
  223. }
  224. $fdetails = &$this->compressed_list[$compressed_file_name];
  225. if ( ! isset($this->compressed_list[$compressed_file_name]))
  226. {
  227. throw new \FuelException('File "<strong>' . $compressed_file_name . '</strong>" is not compressed in the zip.');
  228. return false;
  229. }
  230. if (substr($compressed_file_name, -1) == '/')
  231. {
  232. throw new \FuelException('Trying to unzip a folder name "<strong>' . $compressed_file_name . '</strong>".');
  233. return false;
  234. }
  235. if ( ! $fdetails['uncompressed_size'])
  236. {
  237. $this->set_debug('File "<strong>' . $compressed_file_name . '</strong>" is empty.');
  238. return $target_file_name ? file_put_contents($target_file_name, '') : '';
  239. }
  240. fseek($this->fh, $fdetails['contents_start_offset']);
  241. $ret = $this->_uncompress(
  242. fread($this->fh, $fdetails['compressed_size']),
  243. $fdetails['compression_method'],
  244. $fdetails['uncompressed_size'],
  245. $target_file_name
  246. );
  247. if ($this->apply_chmod AND $target_file_name)
  248. {
  249. chmod($target_file_name, 0644);
  250. }
  251. return $ret;
  252. }
  253. // --------------------------------------------------------------------
  254. /**
  255. * Free the file resource.
  256. *
  257. * @access Public
  258. * @param none
  259. * @return none
  260. */
  261. public function close()
  262. {
  263. // Free the file resource
  264. if ($this->fh)
  265. {
  266. fclose($this->fh);
  267. }
  268. }
  269. // --------------------------------------------------------------------
  270. /**
  271. * Free the file resource Automatic destroy.
  272. *
  273. * @access Public
  274. * @param none
  275. * @return none
  276. */
  277. public function __destroy()
  278. {
  279. $this->close();
  280. }
  281. // --------------------------------------------------------------------
  282. /**
  283. * Uncompress file. And save it to the targetFile.
  284. *
  285. * @access Private
  286. * @param Filecontent, int, int, boolean
  287. * @return none
  288. */
  289. private function _uncompress($content, $mode, $uncompressed_size, $target_file_name = false)
  290. {
  291. switch ($mode)
  292. {
  293. case 0:
  294. return $target_file_name ? file_put_contents($target_file_name, $content) : $content;
  295. case 1:
  296. throw new \FuelException('Shrunk mode is not supported... yet?');
  297. return false;
  298. case 2:
  299. case 3:
  300. case 4:
  301. case 5:
  302. throw new \FuelException('Compression factor ' . ($mode - 1) . ' is not supported... yet?');
  303. return false;
  304. case 6:
  305. throw new \FuelException('Implode is not supported... yet?');
  306. return false;
  307. case 7:
  308. throw new \FuelException('Tokenizing compression algorithm is not supported... yet?');
  309. return false;
  310. case 8:
  311. // Deflate
  312. return $target_file_name ?
  313. file_put_contents($target_file_name, gzinflate($content, $uncompressed_size)) :
  314. gzinflate($content, $uncompressed_size);
  315. case 9:
  316. throw new \FuelException('Enhanced Deflating is not supported... yet?');
  317. return false;
  318. case 10:
  319. throw new \FuelException('PKWARE Date Compression Library Impoloding is not supported... yet?');
  320. return false;
  321. case 12:
  322. // Bzip2
  323. return $target_file_name ?
  324. file_put_contents($target_file_name, bzdecompress($content)) :
  325. bzdecompress($content);
  326. case 18:
  327. throw new \FuelException('IBM TERSE is not supported... yet?');
  328. return false;
  329. default:
  330. throw new \FuelException('Unknown uncompress method: $mode');
  331. return false;
  332. }
  333. }
  334. private function _load_file_list_by_eof(&$fh, $stop_on_file = false)
  335. {
  336. // Check if there's a valid Central Dir signature.
  337. // Let's consider a file comment smaller than 1024 characters...
  338. // Actually, it length can be 65536.. But we're not going to support it.
  339. for ($x = 0; $x < 1024; $x++)
  340. {
  341. fseek($fh, -22 - $x, SEEK_END);
  342. $signature = fread($fh, 4);
  343. if ($signature == $this->central_signature_end)
  344. {
  345. // If found EOF Central Dir
  346. $eodir['disk_number_this'] = unpack("v", fread($fh, 2)); // number of this disk
  347. $eodir['disk_number'] = unpack("v", fread($fh, 2)); // number of the disk with the start of the central directory
  348. $eodir['total_entries_this'] = unpack("v", fread($fh, 2)); // total number of entries in the central dir on this disk
  349. $eodir['total_entries'] = unpack("v", fread($fh, 2)); // total number of entries in
  350. $eodir['size_of_cd'] = unpack("V", fread($fh, 4)); // size of the central directory
  351. $eodir['offset_start_cd'] = unpack("V", fread($fh, 4)); // offset of start of central directory with respect to the starting disk number
  352. $zip_comment_lenght = unpack("v", fread($fh, 2)); // zipfile comment length
  353. $eodir['zipfile_comment'] = $zip_comment_lenght[1] ? fread($fh, $zip_comment_lenght[1]) : ''; // zipfile comment
  354. $this->end_of_central = array(
  355. 'disk_number_this' => $eodir['disk_number_this'][1],
  356. 'disk_number' => $eodir['disk_number'][1],
  357. 'total_entries_this' => $eodir['total_entries_this'][1],
  358. 'total_entries' => $eodir['total_entries'][1],
  359. 'size_of_cd' => $eodir['size_of_cd'][1],
  360. 'offset_start_cd' => $eodir['offset_start_cd'][1],
  361. 'zipfile_comment' => $eodir['zipfile_comment'],
  362. );
  363. // Then, load file list
  364. fseek($fh, $this->end_of_central['offset_start_cd']);
  365. $signature = fread($fh, 4);
  366. while ($signature == $this->dir_signature)
  367. {
  368. $dir['version_madeby'] = unpack("v", fread($fh, 2)); // version made by
  369. $dir['version_needed'] = unpack("v", fread($fh, 2)); // version needed to extract
  370. $dir['general_bit_flag'] = unpack("v", fread($fh, 2)); // general purpose bit flag
  371. $dir['compression_method'] = unpack("v", fread($fh, 2)); // compression method
  372. $dir['lastmod_time'] = unpack("v", fread($fh, 2)); // last mod file time
  373. $dir['lastmod_date'] = unpack("v", fread($fh, 2)); // last mod file date
  374. $dir['crc-32'] = fread($fh, 4); // crc-32
  375. $dir['compressed_size'] = unpack("V", fread($fh, 4)); // compressed size
  376. $dir['uncompressed_size'] = unpack("V", fread($fh, 4)); // uncompressed size
  377. $zip_file_length = unpack("v", fread($fh, 2)); // filename length
  378. $extra_field_length = unpack("v", fread($fh, 2)); // extra field length
  379. $fileCommentLength = unpack("v", fread($fh, 2)); // file comment length
  380. $dir['disk_number_start'] = unpack("v", fread($fh, 2)); // disk number start
  381. $dir['internal_attributes'] = unpack("v", fread($fh, 2)); // internal file attributes-byte1
  382. $dir['external_attributes1'] = unpack("v", fread($fh, 2)); // external file attributes-byte2
  383. $dir['external_attributes2'] = unpack("v", fread($fh, 2)); // external file attributes
  384. $dir['relative_offset'] = unpack("V", fread($fh, 4)); // relative offset of local header
  385. $dir['file_name'] = fread($fh, $zip_file_length[1]); // filename
  386. $dir['extra_field'] = $extra_field_length[1] ? fread($fh, $extra_field_length[1]) : ''; // extra field
  387. $dir['file_comment'] = $fileCommentLength[1] ? fread($fh, $fileCommentLength[1]) : ''; // file comment
  388. // Convert the date and time, from MS-DOS format to UNIX Timestamp
  389. $binary_mod_date = str_pad(decbin($dir['lastmod_date'][1]), 16, '0', STR_PAD_LEFT);
  390. $binary_mod_time = str_pad(decbin($dir['lastmod_time'][1]), 16, '0', STR_PAD_LEFT);
  391. $last_mod_year = bindec(substr($binary_mod_date, 0, 7)) + 1980;
  392. $last_mod_month = bindec(substr($binary_mod_date, 7, 4));
  393. $last_mod_day = bindec(substr($binary_mod_date, 11, 5));
  394. $last_mod_hour = bindec(substr($binary_mod_time, 0, 5));
  395. $last_mod_minute = bindec(substr($binary_mod_time, 5, 6));
  396. $last_mod_second = bindec(substr($binary_mod_time, 11, 5));
  397. $this->central_dir_list[$dir['file_name']] = array(
  398. 'version_madeby' => $dir['version_madeby'][1],
  399. 'version_needed' => $dir['version_needed'][1],
  400. 'general_bit_flag' => str_pad(decbin($dir['general_bit_flag'][1]), 8, '0', STR_PAD_LEFT),
  401. 'compression_method' => $dir['compression_method'][1],
  402. 'lastmod_datetime' => mktime($last_mod_hour, $last_mod_minute, $last_mod_second, $last_mod_month, $last_mod_day, $last_mod_year),
  403. 'crc-32' => str_pad(dechex(ord($dir['crc-32'][3])), 2, '0', STR_PAD_LEFT) .
  404. str_pad(dechex(ord($dir['crc-32'][2])), 2, '0', STR_PAD_LEFT) .
  405. str_pad(dechex(ord($dir['crc-32'][1])), 2, '0', STR_PAD_LEFT) .
  406. str_pad(dechex(ord($dir['crc-32'][0])), 2, '0', STR_PAD_LEFT),
  407. 'compressed_size' => $dir['compressed_size'][1],
  408. 'uncompressed_size' => $dir['uncompressed_size'][1],
  409. 'disk_number_start' => $dir['disk_number_start'][1],
  410. 'internal_attributes' => $dir['internal_attributes'][1],
  411. 'external_attributes1' => $dir['external_attributes1'][1],
  412. 'external_attributes2' => $dir['external_attributes2'][1],
  413. 'relative_offset' => $dir['relative_offset'][1],
  414. 'file_name' => $dir['file_name'],
  415. 'extra_field' => $dir['extra_field'],
  416. 'file_comment' => $dir['file_comment'],
  417. );
  418. $signature = fread($fh, 4);
  419. }
  420. // If loaded centralDirs, then try to identify the offsetPosition of the compressed data.
  421. if ($this->central_dir_list)
  422. {
  423. foreach ($this->central_dir_list as $filename => $details)
  424. {
  425. $i = $this->_get_file_header($fh, $details['relative_offset']);
  426. $this->compressed_list[$filename]['file_name'] = $filename;
  427. $this->compressed_list[$filename]['compression_method'] = $details['compression_method'];
  428. $this->compressed_list[$filename]['version_needed'] = $details['version_needed'];
  429. $this->compressed_list[$filename]['lastmod_datetime'] = $details['lastmod_datetime'];
  430. $this->compressed_list[$filename]['crc-32'] = $details['crc-32'];
  431. $this->compressed_list[$filename]['compressed_size'] = $details['compressed_size'];
  432. $this->compressed_list[$filename]['uncompressed_size'] = $details['uncompressed_size'];
  433. $this->compressed_list[$filename]['lastmod_datetime'] = $details['lastmod_datetime'];
  434. $this->compressed_list[$filename]['extra_field'] = $i['extra_field'];
  435. $this->compressed_list[$filename]['contents_start_offset'] = $i['contents_start_offset'];
  436. if (strtolower($stop_on_file) == strtolower($filename))
  437. {
  438. break;
  439. }
  440. }
  441. }
  442. return TRUE;
  443. }
  444. }
  445. return false;
  446. }
  447. private function _load_files_by_signatures(&$fh, $stop_on_file = false)
  448. {
  449. fseek($fh, 0);
  450. $return = false;
  451. for (;;)
  452. {
  453. $details = $this->_get_file_header($fh);
  454. if ( ! $details)
  455. {
  456. $this->set_debug('Invalid signature. Trying to verify if is old style Data Descriptor...');
  457. fseek($fh, 12 - 4, SEEK_CUR); // 12: Data descriptor - 4: Signature (that will be read again)
  458. $details = $this->_get_file_header($fh);
  459. }
  460. if ( ! $details)
  461. {
  462. $this->set_debug('Still invalid signature. Probably reached the end of the file.');
  463. break;
  464. }
  465. $filename = $details['file_name'];
  466. $this->compressed_list[$filename] = $details;
  467. $return = true;
  468. if (strtolower($stop_on_file) == strtolower($filename))
  469. {
  470. break;
  471. }
  472. }
  473. return $return;
  474. }
  475. private function _get_file_header(&$fh, $start_offset = false)
  476. {
  477. if ($start_offset !== false)
  478. {
  479. fseek($fh, $start_offset);
  480. }
  481. $signature = fread($fh, 4);
  482. if ($signature == $this->zip_signature)
  483. {
  484. // Get information about the zipped file
  485. $file['version_needed'] = unpack("v", fread($fh, 2)); // version needed to extract
  486. $file['general_bit_flag'] = unpack("v", fread($fh, 2)); // general purpose bit flag
  487. $file['compression_method'] = unpack("v", fread($fh, 2)); // compression method
  488. $file['lastmod_time'] = unpack("v", fread($fh, 2)); // last mod file time
  489. $file['lastmod_date'] = unpack("v", fread($fh, 2)); // last mod file date
  490. $file['crc-32'] = fread($fh, 4); // crc-32
  491. $file['compressed_size'] = unpack("V", fread($fh, 4)); // compressed size
  492. $file['uncompressed_size'] = unpack("V", fread($fh, 4)); // uncompressed size
  493. $zip_file_length = unpack("v", fread($fh, 2)); // filename length
  494. $extra_field_length = unpack("v", fread($fh, 2)); // extra field length
  495. $file['file_name'] = fread($fh, $zip_file_length[1]); // filename
  496. $file['extra_field'] = $extra_field_length[1] ? fread($fh, $extra_field_length[1]) : ''; // extra field
  497. $file['contents_start_offset'] = ftell($fh);
  498. // Bypass the whole compressed contents, and look for the next file
  499. fseek($fh, $file['compressed_size'][1], SEEK_CUR);
  500. // Convert the date and time, from MS-DOS format to UNIX Timestamp
  501. $binary_mod_date = str_pad(decbin($file['lastmod_date'][1]), 16, '0', STR_PAD_LEFT);
  502. $binary_mod_time = str_pad(decbin($file['lastmod_time'][1]), 16, '0', STR_PAD_LEFT);
  503. $last_mod_year = bindec(substr($binary_mod_date, 0, 7)) + 1980;
  504. $last_mod_month = bindec(substr($binary_mod_date, 7, 4));
  505. $last_mod_day = bindec(substr($binary_mod_date, 11, 5));
  506. $last_mod_hour = bindec(substr($binary_mod_time, 0, 5));
  507. $last_mod_minute = bindec(substr($binary_mod_time, 5, 6));
  508. $last_mod_second = bindec(substr($binary_mod_time, 11, 5));
  509. // Mount file table
  510. $i = array(
  511. 'file_name' => $file['file_name'],
  512. 'compression_method' => $file['compression_method'][1],
  513. 'version_needed' => $file['version_needed'][1],
  514. 'lastmod_datetime' => mktime($last_mod_hour, $last_mod_minute, $last_mod_second, $last_mod_month, $last_mod_day, $last_mod_year),
  515. 'crc-32' => str_pad(dechex(ord($file['crc-32'][3])), 2, '0', STR_PAD_LEFT) .
  516. str_pad(dechex(ord($file['crc-32'][2])), 2, '0', STR_PAD_LEFT) .
  517. str_pad(dechex(ord($file['crc-32'][1])), 2, '0', STR_PAD_LEFT) .
  518. str_pad(dechex(ord($file['crc-32'][0])), 2, '0', STR_PAD_LEFT),
  519. 'compressed_size' => $file['compressed_size'][1],
  520. 'uncompressed_size' => $file['uncompressed_size'][1],
  521. 'extra_field' => $file['extra_field'],
  522. 'general_bit_flag' => str_pad(decbin($file['general_bit_flag'][1]), 8, '0', STR_PAD_LEFT),
  523. 'contents_start_offset' => $file['contents_start_offset']
  524. );
  525. return $i;
  526. }
  527. return false;
  528. }
  529. }