1 | <?php |
||
14 | class ZipFile |
||
15 | { |
||
16 | /** |
||
17 | * Array to store compressed data. |
||
18 | * |
||
19 | * @private array $datasec |
||
20 | */ |
||
21 | private $datasec = []; |
||
22 | /** |
||
23 | * Central directory. |
||
24 | * |
||
25 | * @private array $ctrl_dir |
||
26 | */ |
||
27 | private $ctrl_dir = []; |
||
28 | /** |
||
29 | * End of central directory record. |
||
30 | * |
||
31 | * @private string $eof_ctrl_dir |
||
32 | */ |
||
33 | private $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; |
||
34 | /** |
||
35 | * Last offset position. |
||
36 | * |
||
37 | * @private integer $old_offset |
||
38 | */ |
||
39 | private $old_offset = 0; |
||
40 | |||
41 | /** |
||
42 | * Converts an Unix timestamp to a four byte DOS date and time format (date |
||
43 | * in high two bytes, time in low two bytes allowing magnitude comparison). |
||
44 | * |
||
45 | * @param int $unixtime the current Unix timestamp |
||
46 | * |
||
47 | * @return int the current date in a four byte DOS format |
||
48 | */ |
||
49 | 38 | public function unix2DosTime($unixtime = 0) |
|
50 | { |
||
51 | 38 | $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime); |
|
52 | 38 | if ($timearray['year'] < 1980) { |
|
53 | $timearray['year'] = 1980; |
||
54 | $timearray['mon'] = 1; |
||
55 | $timearray['mday'] = 1; |
||
56 | $timearray['hours'] = 0; |
||
57 | $timearray['minutes'] = 0; |
||
58 | $timearray['seconds'] = 0; |
||
59 | } // end if |
||
60 | 38 | return (($timearray['year'] - 1980) << 25) |
|
61 | 38 | | ($timearray['mon'] << 21) |
|
62 | 38 | | ($timearray['mday'] << 16) |
|
63 | 38 | | ($timearray['hours'] << 11) |
|
64 | 38 | | ($timearray['minutes'] << 5) |
|
65 | 38 | | ($timearray['seconds'] >> 1); |
|
66 | } |
||
67 | |||
68 | // end of the 'unix2DosTime()' method |
||
69 | |||
70 | /** |
||
71 | * Adds "file" to archive. |
||
72 | * |
||
73 | * @param string $data file contents |
||
74 | * @param string $name name of the file in the archive (may contains the path) |
||
75 | * @param int $time the current timestamp |
||
76 | */ |
||
77 | 38 | public function addFile($data, $name, $time = 0) |
|
126 | |||
127 | // end of the 'addFile()' method |
||
128 | |||
129 | /** |
||
130 | * Echo central dir if ->doWrite==true, else build string to return. |
||
131 | * |
||
132 | * @return string if ->doWrite {empty string} else the ZIP file contents |
||
133 | */ |
||
134 | 38 | public function file() |
|
150 | |||
151 | // end of the 'file()' method |
||
152 | } |
||
153 |