Documentation TYPO3 par Ameos

zip.lib.php

00001 <?php
00002 /* $Id: zip.lib.php,v 2.4 2004/11/03 13:56:52 garvinhicking Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 
00025 class zipfile
00026 {
00032     var $datasec      = array();
00033 
00039     var $ctrl_dir     = array();
00040 
00046     var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
00047 
00053     var $old_offset   = 0;
00054 
00055 
00066     function unix2DosTime($unixtime = 0) {
00067         $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
00068 
00069         if ($timearray['year'] < 1980) {
00070             $timearray['year']    = 1980;
00071             $timearray['mon']     = 1;
00072             $timearray['mday']    = 1;
00073             $timearray['hours']   = 0;
00074             $timearray['minutes'] = 0;
00075             $timearray['seconds'] = 0;
00076         } // end if
00077 
00078         return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
00079                 ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
00080     } // end of the 'unix2DosTime()' method
00081 
00082 
00092     function addFile($data, $name, $time = 0)
00093     {
00094         $name     = str_replace('\\', '/', $name);
00095 
00096         $dtime    = dechex($this->unix2DosTime($time));
00097         $hexdtime = '\x' . $dtime[6] . $dtime[7]
00098                   . '\x' . $dtime[4] . $dtime[5]
00099                   . '\x' . $dtime[2] . $dtime[3]
00100                   . '\x' . $dtime[0] . $dtime[1];
00101         eval('$hexdtime = "' . $hexdtime . '";');
00102 
00103         $fr   = "\x50\x4b\x03\x04";
00104         $fr   .= "\x14\x00";            // ver needed to extract
00105         $fr   .= "\x00\x00";            // gen purpose bit flag
00106         $fr   .= "\x08\x00";            // compression method
00107         $fr   .= $hexdtime;             // last mod time and date
00108 
00109         // "local file header" segment
00110         $unc_len = strlen($data);
00111         $crc     = crc32($data);
00112         $zdata   = gzcompress($data);
00113         $zdata   = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug
00114         $c_len   = strlen($zdata);
00115         $fr      .= pack('V', $crc);             // crc32
00116         $fr      .= pack('V', $c_len);           // compressed filesize
00117         $fr      .= pack('V', $unc_len);         // uncompressed filesize
00118         $fr      .= pack('v', strlen($name));    // length of filename
00119         $fr      .= pack('v', 0);                // extra field length
00120         $fr      .= $name;
00121 
00122         // "file data" segment
00123         $fr .= $zdata;
00124 
00125         // "data descriptor" segment (optional but necessary if archive is not
00126         // served as file)
00127         // nijel(2004-10-19): this seems not to be needed at all and causes
00128         // problems in some cases (bug #1037737)
00129         //$fr .= pack('V', $crc);                 // crc32
00130         //$fr .= pack('V', $c_len);               // compressed filesize
00131         //$fr .= pack('V', $unc_len);             // uncompressed filesize
00132 
00133         // add this entry to array
00134         $this -> datasec[] = $fr;
00135 
00136         // now add to central directory record
00137         $cdrec = "\x50\x4b\x01\x02";
00138         $cdrec .= "\x00\x00";                // version made by
00139         $cdrec .= "\x14\x00";                // version needed to extract
00140         $cdrec .= "\x00\x00";                // gen purpose bit flag
00141         $cdrec .= "\x08\x00";                // compression method
00142         $cdrec .= $hexdtime;                 // last mod time & date
00143         $cdrec .= pack('V', $crc);           // crc32
00144         $cdrec .= pack('V', $c_len);         // compressed filesize
00145         $cdrec .= pack('V', $unc_len);       // uncompressed filesize
00146         $cdrec .= pack('v', strlen($name) ); // length of filename
00147         $cdrec .= pack('v', 0 );             // extra field length
00148         $cdrec .= pack('v', 0 );             // file comment length
00149         $cdrec .= pack('v', 0 );             // disk number start
00150         $cdrec .= pack('v', 0 );             // internal file attributes
00151         $cdrec .= pack('V', 32 );            // external file attributes - 'archive' bit set
00152 
00153         $cdrec .= pack('V', $this -> old_offset ); // relative offset of local header
00154         $this -> old_offset += strlen($fr);
00155 
00156         $cdrec .= $name;
00157 
00158         // optional extra field, file comment goes here
00159         // save to central directory
00160         $this -> ctrl_dir[] = $cdrec;
00161     } // end of the 'addFile()' method
00162 
00163 
00171     function file()
00172     {
00173         $data    = implode('', $this -> datasec);
00174         $ctrldir = implode('', $this -> ctrl_dir);
00175 
00176         return
00177             $data .
00178             $ctrldir .
00179             $this -> eof_ctrl_dir .
00180             pack('v', sizeof($this -> ctrl_dir)) .  // total # of entries "on this disk"
00181             pack('v', sizeof($this -> ctrl_dir)) .  // total # of entries overall
00182             pack('V', strlen($ctrldir)) .           // size of central dir
00183             pack('V', strlen($data)) .              // offset to start of central dir
00184             "\x00\x00";                             // .zip file comment length
00185     } // end of the 'file()' method
00186 
00187 } // end of the 'zipfile' class
00188 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6