| 135 | | /* |
|---|
| 136 | | register the file into the central directory record |
|---|
| 137 | | it contains an header for each file |
|---|
| 138 | | - central file header signature 4 bytes (0x02014b50) |
|---|
| 139 | | - version made by 2 bytes 0=DOS |
|---|
| 140 | | - version needed to extract 2 bytes 0x14 |
|---|
| 141 | | - general purpose bit flag 2 bytes 0 |
|---|
| 142 | | - compression method 2 bytes 0x8 |
|---|
| 143 | | - last mod file time 2 bytes (fileinfo) |
|---|
| 144 | | - last mod file date 2 bytes (fileinfo) |
|---|
| 145 | | - crc-32 4 bytes (fileinfo) |
|---|
| 146 | | - compressed size 4 bytes (fileinfo) |
|---|
| 147 | | - uncompressed size 4 bytes (fileinfo) |
|---|
| 148 | | - file name length 2 bytes (fileinfo) |
|---|
| 149 | | - extra field length 2 bytes 0 (fileinfo) |
|---|
| 150 | | - file comment length 2 bytes 0 |
|---|
| 151 | | - disk number start 2 bytes 0 |
|---|
| 152 | | - internal file attributes 2 bytes 0 |
|---|
| 153 | | - external file attributes 4 bytes 32 : 'archive' bit set |
|---|
| 154 | | - relative offset of local header 4 bytes |
|---|
| 155 | | - file name (variable size) |
|---|
| 156 | | - extra field (variable size) |
|---|
| 157 | | - file comment (variable size) |
|---|
| 158 | | */ |
|---|
| 159 | | $cdrecord = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00".$fileinfo; |
|---|
| 160 | | $cdrecord .= "\x00\x00\x00\x00\x00\x00"; |
|---|
| 161 | | $cdrecord .= pack('V', 32); |
|---|
| 162 | | $cdrecord .= pack('V', $this ->centralDirOffset ); |
|---|
| 163 | | $cdrecord .= $zipFileName; |
|---|
| | 128 | $this->centralDirOffset += strlen($filerecord); |
|---|
| | 190 | |
|---|
| | 191 | |
|---|
| | 192 | |
|---|
| | 193 | protected function _getDOSTimeFormat($timestamp){ |
|---|
| | 194 | // converts unix timestamp to dos binary format |
|---|
| | 195 | if($timestamp == 0) |
|---|
| | 196 | $timestamp = time(); |
|---|
| | 197 | elseif($timestamp < 315529200) // 01/01/1980 |
|---|
| | 198 | $timestamp = 315529200; |
|---|
| | 199 | |
|---|
| | 200 | $dt = getdate($timestamp); |
|---|
| | 201 | |
|---|
| | 202 | return pack('V',($dt['seconds'] >> 1) | ($dt['minutes'] << 5) | ($dt['hours'] << 11) | |
|---|
| | 203 | ($dt['mday'] << 16) | ($dt['mon'] << 21) | (($dt['year'] - 1980) << 25)); |
|---|
| | 204 | |
|---|
| | 205 | } |
|---|
| | 206 | |
|---|
| | 207 | protected function _addCentralDirEntry($name, $info, $isDir = false){ |
|---|
| | 208 | /* |
|---|
| | 209 | register the file into the central directory record |
|---|
| | 210 | it contains an header for each file |
|---|
| | 211 | - central file header signature 4 bytes (0x02014b50) |
|---|
| | 212 | - version made by 2 bytes 0=DOS |
|---|
| | 213 | - version needed to extract 2 bytes 0x14 |
|---|
| | 214 | - general purpose bit flag 2 bytes 0 |
|---|
| | 215 | - compression method 2 bytes 0x8 |
|---|
| | 216 | - last mod file time 2 bytes (fileinfo) |
|---|
| | 217 | - last mod file date 2 bytes (fileinfo) |
|---|
| | 218 | - crc-32 4 bytes (fileinfo) |
|---|
| | 219 | - compressed size 4 bytes (fileinfo) |
|---|
| | 220 | - uncompressed size 4 bytes (fileinfo) |
|---|
| | 221 | - file name length 2 bytes (fileinfo) |
|---|
| | 222 | - extra field length 2 bytes 0 (fileinfo) |
|---|
| | 223 | - file comment length 2 bytes 0 |
|---|
| | 224 | - disk number start 2 bytes 0 |
|---|
| | 225 | - internal file attributes 2 bytes 0 |
|---|
| | 226 | - external file attributes 4 bytes 32 : 'archive' bit set ; 16 : for empty folder support |
|---|
| | 227 | - relative offset of local header 4 bytes |
|---|
| | 228 | - file name (variable size) |
|---|
| | 229 | - extra field (variable size) |
|---|
| | 230 | - file comment (variable size) |
|---|
| | 231 | */ |
|---|
| | 232 | |
|---|
| | 233 | $cdrecord = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00".$info; |
|---|
| | 234 | $cdrecord .= "\x00\x00\x00\x00\x00\x00"; |
|---|
| | 235 | if($isDir) |
|---|
| | 236 | $cdrecord .= pack('V', 16); |
|---|
| | 237 | else |
|---|
| | 238 | $cdrecord .= pack('V', 32); |
|---|
| | 239 | $cdrecord .= pack('V', $this ->centralDirOffset ); |
|---|
| | 240 | $cdrecord .= $name; |
|---|
| | 241 | |
|---|
| | 242 | $this->centralDirectory[] = $cdrecord; |
|---|
| | 243 | } |
|---|