Documentation TYPO3 par Ameos

zip.lib.php

00001 <?php
00002 /* $Id: zip.lib.php,v 2.1 2003/11/20 16:31:50 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         $fr .= pack('V', $crc);                 // crc32
00128         $fr .= pack('V', $c_len);               // compressed filesize
00129         $fr .= pack('V', $unc_len);             // uncompressed filesize
00130 
00131         // add this entry to array
00132         $this -> datasec[] = $fr;
00133 
00134         // now add to central directory record
00135         $cdrec = "\x50\x4b\x01\x02";
00136         $cdrec .= "\x00\x00";                // version made by
00137         $cdrec .= "\x14\x00";                // version needed to extract
00138         $cdrec .= "\x00\x00";                // gen purpose bit flag
00139         $cdrec .= "\x08\x00";                // compression method
00140         $cdrec .= $hexdtime;                 // last mod time & date
00141         $cdrec .= pack('V', $crc);           // crc32
00142         $cdrec .= pack('V', $c_len);         // compressed filesize
00143         $cdrec .= pack('V', $unc_len);       // uncompressed filesize
00144         $cdrec .= pack('v', strlen($name) ); // length of filename
00145         $cdrec .= pack('v', 0 );             // extra field length
00146         $cdrec .= pack('v', 0 );             // file comment length
00147         $cdrec .= pack('v', 0 );             // disk number start
00148         $cdrec .= pack('v', 0 );             // internal file attributes
00149         $cdrec .= pack('V', 32 );            // external file attributes - 'archive' bit set
00150 
00151         $cdrec .= pack('V', $this -> old_offset ); // relative offset of local header
00152         $this -> old_offset += strlen($fr);
00153 
00154         $cdrec .= $name;
00155 
00156         // optional extra field, file comment goes here
00157         // save to central directory
00158         $this -> ctrl_dir[] = $cdrec;
00159     } // end of the 'addFile()' method
00160 
00161 
00169     function file()
00170     {
00171         $data    = implode('', $this -> datasec);
00172         $ctrldir = implode('', $this -> ctrl_dir);
00173 
00174         return
00175             $data .
00176             $ctrldir .
00177             $this -> eof_ctrl_dir .
00178             pack('v', sizeof($this -> ctrl_dir)) .  // total # of entries "on this disk"
00179             pack('v', sizeof($this -> ctrl_dir)) .  // total # of entries overall
00180             pack('V', strlen($ctrldir)) .           // size of central dir
00181             pack('V', strlen($data)) .              // offset to start of central dir
00182             "\x00\x00";                             // .zip file comment length
00183     } // end of the 'file()' method
00184 
00185 } // end of the 'zipfile' class
00186 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6