| | 184 | $time = pack('V',($dt['seconds'] >> 1) | ($dt['minutes'] << 5) | ($dt['hours'] << 11) | |
|---|
| | 185 | ($dt['mday'] << 16) | ($dt['mon'] << 21) | (($dt['year'] - 1980) << 25)); |
|---|
| | 186 | |
|---|
| | 187 | /* |
|---|
| | 188 | generation of the file record |
|---|
| | 189 | |
|---|
| | 190 | file record: |
|---|
| | 191 | - local file header signature 4 bytes (0x04034b50) |
|---|
| | 192 | - version needed to extract 2 bytes 14 |
|---|
| | 193 | - general purpose bit flag 2 bytes 0 |
|---|
| | 194 | - compression method 2 bytes 0x8 |
|---|
| | 195 | - last mod file time 2 bytes (fileinfo) |
|---|
| | 196 | - last mod file date 2 bytes (fileinfo) |
|---|
| | 197 | - crc-32 4 bytes (fileinfo) |
|---|
| | 198 | - compressed size 4 bytes (fileinfo) |
|---|
| | 199 | - uncompressed size 4 bytes (fileinfo) |
|---|
| | 200 | - file name length 2 bytes (fileinfo) |
|---|
| | 201 | - extra field length 2 bytes (here 0) (fileinfo) |
|---|
| | 202 | - file name (variable size) |
|---|
| | 203 | - extra field (variable size) (here nothing) |
|---|
| | 204 | - compressed content |
|---|
| | 205 | */ |
|---|
| | 206 | $name = str_replace('\\', '/', $name); |
|---|
| | 207 | |
|---|
| | 208 | $fileinfo = $time.pack('V', crc32('')); |
|---|
| | 209 | $fileinfo .= pack('V', 0). pack('V', 0); |
|---|
| | 210 | $fileinfo .= pack('v', strlen($name))."\x00\x00"; |
|---|
| | 211 | |
|---|
| | 212 | $filerecord = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00"; |
|---|
| | 213 | $filerecord .= $fileinfo.$name; |
|---|
| | 214 | |
|---|
| | 215 | $this->fileRecords[] = $filerecord; |
|---|
| | 216 | |
|---|
| | 217 | |
|---|
| | 218 | /* |
|---|
| | 219 | register the file into the central directory record |
|---|
| | 220 | it contains an header for each file |
|---|
| | 221 | - central file header signature 4 bytes (0x02014b50) |
|---|
| | 222 | - version made by 2 bytes 0=DOS |
|---|
| | 223 | - version needed to extract 2 bytes 0x14 |
|---|
| | 224 | - general purpose bit flag 2 bytes 0 |
|---|
| | 225 | - compression method 2 bytes 0x8 |
|---|
| | 226 | - last mod file time 2 bytes (fileinfo) |
|---|
| | 227 | - last mod file date 2 bytes (fileinfo) |
|---|
| | 228 | - crc-32 4 bytes (fileinfo) |
|---|
| | 229 | - compressed size 4 bytes (fileinfo) |
|---|
| | 230 | - uncompressed size 4 bytes (fileinfo) |
|---|
| | 231 | - file name length 2 bytes (fileinfo) |
|---|
| | 232 | - extra field length 2 bytes 0 (fileinfo) |
|---|
| | 233 | - file comment length 2 bytes 0 |
|---|
| | 234 | - disk number start 2 bytes 0 |
|---|
| | 235 | - internal file attributes 2 bytes 0 |
|---|
| | 236 | - external file attributes 4 bytes 32 : 'archive' bit set |
|---|
| | 237 | - relative offset of local header 4 bytes |
|---|
| | 238 | - file name (variable size) |
|---|
| | 239 | - extra field (variable size) |
|---|
| | 240 | - file comment (variable size) |
|---|
| | 241 | */ |
|---|
| | 242 | $cdrecord = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00".$fileinfo; |
|---|
| | 243 | $cdrecord .= "\x00\x00\x00\x00\x00\x00"; |
|---|
| | 244 | $cdrecord .= pack('V', 16); |
|---|
| | 245 | $cdrecord .= pack('V', $this ->centralDirOffset ); |
|---|
| | 246 | $cdrecord .= $name; |
|---|
| | 247 | |
|---|
| | 248 | $this->centralDirectory[] = $cdrecord; |
|---|
| | 249 | |
|---|
| | 250 | $this->centralDirOffset += strlen($filerecord); |
|---|
| | 251 | } |
|---|
| | 252 | |
|---|
| | 253 | |
|---|