Back to index

php5  5.3.10
phar_test.inc
Go to the documentation of this file.
00001 <?php
00002 
00003 if (function_exists('date_default_timezone_set')) {
00004        date_default_timezone_set('UTC');
00005 }
00006 
00007 $manifest = (binary)'';
00008 $glags = 0;
00009 
00010 foreach($files as $name => $cont)
00011 {
00012        global $gflags, $files;
00013 
00014        $comp = NULL;
00015        $crc32= NULL;
00016        $clen = NULL;
00017        $ulen = NULL;
00018        $time = isset($ftime) ? $ftime : @mktime(12, 0, 0, 3, 1, 2006);
00019        $flags= 0;
00020        $perm = 0x000001B6;
00021        $meta = NULL;
00022 
00023        // overwrite if array
00024        if (is_array($cont))
00025        {
00026               foreach(array('comp','crc32','clen','ulen','time','flags','perm','meta','cont') as $what)
00027               {
00028                      if (isset($cont[$what]))
00029                      {
00030                             $$what = $cont[$what];
00031                      }
00032               }
00033        }
00034 
00035        // create if not yet done
00036        if (empty($comp)) $comp = $cont;
00037        if (empty($ulen)) $ulen = strlen($cont);
00038        if (empty($clen)) $clen = strlen($comp);
00039        if (empty($crc32))$crc32= crc32((binary)$cont);
00040        if (isset($meta)) $meta = serialize($meta);
00041 
00042        // write manifest entry
00043        $manifest .= pack('V', strlen($name)) . (binary)$name;
00044        $manifest .= pack('VVVVVV', $ulen, $time, $clen, $crc32, $flags|$perm, strlen($meta)) . (binary)$meta;
00045 
00046        // globals
00047        $gflags |= $flags;
00048        $files[$name] = $comp;
00049 }
00050 
00051 if (!isset($alias)) $alias = 'hio';
00052 
00053 if (isset($pmeta)) $pmeta = serialize($pmeta); else $pmeta = '';
00054 
00055 $manifest = pack('VnVV', count($files), isset($hasdir) ? 0x1110 : 0x1000, $gflags, strlen($alias)) . (binary)$alias . pack('V', strlen($pmeta)) . (binary)$pmeta . $manifest;
00056 $file = (binary)$file;
00057 $file .= pack('V', strlen($manifest)) . $manifest;
00058 
00059 foreach($files as $cont)
00060 {
00061        $file .= (binary)$cont;
00062 }
00063 
00064 file_put_contents($fname, $file);
00065 
00066 if (@$gzip) {
00067        $fp = gzopen($fname, 'w');
00068        fwrite($fp, $file);
00069        fclose($fp);
00070 }
00071 
00072 if (@$bz2) {
00073        $fp = bzopen($fname, 'w');
00074        fwrite($fp, $file);
00075        fclose($fp);
00076 }
00077 
00078 ?>