phar_test.inc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. date_default_timezone_set('UTC');
  3. $manifest = (binary)'';
  4. $gflags = 0;
  5. foreach($files as $name => $cont)
  6. {
  7. global $gflags, $files;
  8. $comp = NULL;
  9. $crc32= NULL;
  10. $clen = NULL;
  11. $ulen = NULL;
  12. $time = isset($ftime) ? $ftime : @mktime(12, 0, 0, 3, 1, 2006);
  13. $flags= 0;
  14. $perm = 0x000001B6;
  15. $meta = NULL;
  16. // overwrite if array
  17. if (is_array($cont))
  18. {
  19. foreach(array('comp','crc32','clen','ulen','time','flags','perm','meta','cont') as $what)
  20. {
  21. if (isset($cont[$what]))
  22. {
  23. $$what = $cont[$what];
  24. }
  25. }
  26. }
  27. // create if not yet done
  28. if (empty($comp)) $comp = $cont;
  29. if (empty($ulen)) $ulen = strlen($cont);
  30. if (empty($clen)) $clen = strlen($comp);
  31. if (empty($crc32))$crc32= crc32((binary)$cont);
  32. $meta = isset($meta) ? serialize($meta) : "";
  33. // write manifest entry
  34. $manifest .= pack('V', strlen($name)) . (binary)$name;
  35. $manifest .= pack('VVVVVV', $ulen, $time, $clen, $crc32, $flags|$perm, strlen($meta)) . (binary)$meta;
  36. // globals
  37. $gflags |= $flags;
  38. $files[$name] = $comp;
  39. }
  40. if (!isset($alias)) $alias = 'hio';
  41. if (isset($pmeta)) $pmeta = serialize($pmeta); else $pmeta = '';
  42. $manifest = pack('VnVV', count($files), isset($hasdir) ? 0x1110 : 0x1000, $gflags, strlen($alias)) . (binary)$alias . pack('V', strlen($pmeta)) . (binary)$pmeta . $manifest;
  43. $file = (binary)$file;
  44. $file .= pack('V', strlen($manifest)) . $manifest;
  45. foreach($files as $cont)
  46. {
  47. $file .= (binary)$cont;
  48. }
  49. file_put_contents($fname, $file);
  50. if (@$gzip) {
  51. $fp = gzopen($fname, 'w');
  52. fwrite($fp, $file);
  53. fclose($fp);
  54. }
  55. if (@$bz2) {
  56. $fp = bzopen($fname, 'w');
  57. fwrite($fp, $file);
  58. fclose($fp);
  59. }
  60. ?>