|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* XOOPS zip downloader |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright XOOPS Project (http://xoops.org) |
|
16
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
17
|
|
|
* @package class |
|
18
|
|
|
* @since 2.0.0 |
|
19
|
|
|
* @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ |
|
20
|
|
|
* @version $Id$ |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Abstract base class for forms |
|
25
|
|
|
* |
|
26
|
|
|
* @author Kazumi Ono <[email protected]> |
|
27
|
|
|
* @author John Neill <[email protected]> |
|
28
|
|
|
* @copyright copyright (c) XOOPS.org |
|
29
|
|
|
* @package class |
|
30
|
|
|
*/ |
|
31
|
|
|
class XoopsZipDownloader extends XoopsDownloader |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Constructor |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $ext extention |
|
37
|
|
|
* @param string $mimyType mimi type |
|
38
|
|
|
* |
|
39
|
|
|
* @return XoopsZipDownloader |
|
40
|
|
|
*/ |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
1 |
|
public function __construct($ext = '.zip', $mimyType = 'application/x-zip') |
|
43
|
|
|
{ |
|
44
|
1 |
|
$this->archiver = new zipfile(); |
|
|
|
|
|
|
45
|
1 |
|
$this->ext = trim($ext); |
|
46
|
1 |
|
$this->mimeType = trim($mimyType); |
|
|
|
|
|
|
47
|
1 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Add file |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $filepath path |
|
53
|
|
|
* @param string $newfilename name |
|
54
|
|
|
* |
|
55
|
|
|
* @return false|null |
|
56
|
|
|
*/ |
|
57
|
|
View Code Duplication |
public function addFile($filepath, $newfilename = null) |
|
58
|
|
|
{ |
|
59
|
|
|
// Read in the file's contents |
|
60
|
|
|
$fp = @fopen($filepath, "r"); |
|
61
|
|
|
if ($fp === false) { |
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
$data = fread($fp, filesize($filepath)); |
|
65
|
|
|
fclose($fp); |
|
66
|
|
|
$filename = (isset($newfilename) && trim($newfilename) != '') ? trim($newfilename) : $filepath; |
|
67
|
|
|
$result = $this->archiver->addFile($data, $filename, filemtime($filename)); |
|
|
|
|
|
|
68
|
|
|
return $result; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Add Binary File |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $filepath path |
|
75
|
|
|
* @param string $newfilename name |
|
76
|
|
|
* |
|
77
|
|
|
* @return false|null |
|
78
|
|
|
*/ |
|
79
|
|
View Code Duplication |
public function addBinaryFile($filepath, $newfilename = null) |
|
80
|
|
|
{ |
|
81
|
|
|
// Read in the file's contents |
|
82
|
|
|
$fp = @fopen($filepath, "rb"); |
|
83
|
|
|
if ($fp === false) { |
|
84
|
|
|
return false; |
|
85
|
|
|
} |
|
86
|
|
|
$data = fread($fp, filesize($filepath)); |
|
87
|
|
|
fclose($fp); |
|
88
|
|
|
$filename = (isset($newfilename) && trim($newfilename) != '') ? trim($newfilename) : $filepath; |
|
89
|
|
|
$result = $this->archiver->addFile($data, $filename, filemtime($filename)); |
|
|
|
|
|
|
90
|
|
|
return $result; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Add File Data |
|
95
|
|
|
* |
|
96
|
|
|
* @param string &$data data |
|
97
|
|
|
* @param string $filename name |
|
98
|
|
|
* @param int $time time |
|
99
|
|
|
* |
|
100
|
|
|
* @return result |
|
101
|
|
|
*/ |
|
102
|
|
|
public function addFileData(&$data, $filename, $time = 0) |
|
103
|
|
|
{ |
|
104
|
|
|
$result = $this->archiver->addFile($data, $filename, $time); |
|
|
|
|
|
|
105
|
|
|
return $result; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Add Binary File Data |
|
110
|
|
|
* |
|
111
|
|
|
* @param string &$data data |
|
112
|
|
|
* @param string $filename name |
|
113
|
|
|
* @param int $time file time |
|
114
|
|
|
* |
|
115
|
|
|
* @return result|null |
|
116
|
|
|
*/ |
|
117
|
|
|
public function addBinaryFileData(&$data, $filename, $time = 0) |
|
118
|
|
|
{ |
|
119
|
|
|
$result = $this->addFileData($data, $filename, $time); |
|
120
|
|
|
return $result; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Fownload Data as a Zip file |
|
125
|
|
|
* |
|
126
|
|
|
* @param string $name zip name |
|
127
|
|
|
* @param bool $gzip unused |
|
128
|
|
|
* |
|
129
|
|
|
* @return void |
|
130
|
|
|
*/ |
|
131
|
|
|
public function download($name, $gzip = true) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->_header($name . $this->ext); |
|
134
|
|
|
$result = $this->archiver->file(); |
|
|
|
|
|
|
135
|
|
|
if ($result !== false) { |
|
136
|
|
|
echo $result; |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.