1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
,
numfiles => 0,
fullfilepath =>
);
private $filehash = ;
private $zip = ;
public function __construct($settings) {
$this->zipfile($settings);
}
public function zipfile($settings) {
$this->zip = new ziparchive();
$this->settings = new stdclass();
foreach ($settings as $k => $v) {
$this->settings->$k = $v;
}
}
public function create() {
$this->filehash = md5(implode(,, $this->files));
$this->fileinfo[name] = $this->filehash . .zip;
$this->fileinfo[numfiles] = count($this->files);
$this->fileinfo[fullfilepath] = $this->settings->path .
/ . $this->fileinfo[name];
if (file_exists($this->fileinfo[fullfilepath])) {
return array (
false,
already created: . $this->fileinfo[fullfilepath]
);
}
else {
$this->zip->open($this->fileinfo[fullfilepath], ziparchive::create);
$this->addfiles();
$this->zip->close();
return array (
true,
new file created: . $this->fileinfo[fullfilepath]
);
}
}
private function addfiles() {
foreach ($this->files as $k) {
$this->zip->addfile($k, basename($k));
}
}
}
$settings = array (
path => dirname(__file__)
);
$zipfile = new zipfile($settings);
$zipfile->files = array (
./images/navoff.jpg,
./images/navon.jpg
);
list($success, $error) = $zipfile->create();
if ($success === true) {
//success
}
else {
//error because: $error
}
?>
http://www.bkjia.com/phpjc/980113.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/980113.htmltecharticlephp生成zip文件类实例 具体如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 4...
