1 | <?php |
||
23 | class FileUpload extends RequestPlugin |
||
24 | { |
||
25 | use \Jaxon\Features\Config; |
||
26 | use \Jaxon\Features\Validator; |
||
27 | use \Jaxon\Features\Translator; |
||
28 | |||
29 | /** |
||
30 | * The uploaded files copied in the user dir |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $aUserFiles = []; |
||
35 | |||
36 | /** |
||
37 | * The name of file containing upload data |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $sTempFile = ''; |
||
42 | |||
43 | /** |
||
44 | * The subdir where uploaded files are stored |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $sUploadSubdir = ''; |
||
49 | |||
50 | /** |
||
51 | * Is the current request an HTTP upload |
||
52 | * |
||
53 | * @var boolean |
||
54 | */ |
||
55 | protected $bRequestIsHttpUpload = false; |
||
56 | |||
57 | /** |
||
58 | * HTTP file upload support |
||
59 | * |
||
60 | * @var Support |
||
61 | */ |
||
62 | protected $xSupport = null; |
||
63 | |||
64 | /** |
||
65 | * The constructor |
||
66 | * |
||
67 | * @param Support $xSupport HTTP file upload support |
||
68 | */ |
||
69 | public function __construct(Support $xSupport) |
||
83 | |||
84 | /** |
||
85 | * Set the uploaded file name sanitizer |
||
86 | * |
||
87 | * @param Closure $cSanitizer The closure |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | public function sanitizer(Closure $cSanitizer) |
||
95 | |||
96 | /** |
||
97 | * Get the uploaded files |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | public function files() |
||
105 | |||
106 | /** |
||
107 | * Make sure the upload dir exists and is writable |
||
108 | * |
||
109 | * @param string $sUploadDir The filename |
||
110 | * @param string $sUploadSubDir The filename |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | private function _makeUploadDir($sUploadDir, $sUploadSubDir) |
||
129 | |||
130 | /** |
||
131 | * Get the path to the upload dir |
||
132 | * |
||
133 | * @param string $sFieldId The filename |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | protected function getUploadDir($sFieldId) |
||
145 | |||
146 | /** |
||
147 | * Get the path to the upload temp dir |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | protected function getUploadTempDir() |
||
158 | |||
159 | /** |
||
160 | * Get the path to the upload temp file |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | protected function getUploadTempFile() |
||
176 | |||
177 | /** |
||
178 | * Read uploaded files info from HTTP request data |
||
179 | * |
||
180 | * @return void |
||
181 | */ |
||
182 | protected function readFromHttpData() |
||
204 | |||
205 | /** |
||
206 | * Save uploaded files info to a temp file |
||
207 | * |
||
208 | * @return void |
||
209 | */ |
||
210 | protected function saveToTempFile() |
||
227 | |||
228 | /** |
||
229 | * Read uploaded files info from a temp file |
||
230 | * |
||
231 | * @return void |
||
232 | */ |
||
233 | protected function readFromTempFile() |
||
248 | |||
249 | /** |
||
250 | * Return the name of this plugin |
||
251 | * |
||
252 | * @return string |
||
253 | */ |
||
254 | public function getName() |
||
258 | |||
259 | /** |
||
260 | * Generate a hash for the registered browser events |
||
261 | * |
||
262 | * @return string |
||
263 | */ |
||
264 | public function generateHash() |
||
268 | |||
269 | /** |
||
270 | * Generate client side javascript code for the registered browser events |
||
271 | * |
||
272 | * @return string |
||
273 | */ |
||
274 | public function getScript() |
||
278 | |||
279 | /** |
||
280 | * Inform this plugin that other plugin can process the current request |
||
281 | * |
||
282 | * @return void |
||
283 | */ |
||
284 | public function noRequestPluginFound() |
||
291 | |||
292 | /** |
||
293 | * Check if this plugin can process the incoming Jaxon request |
||
294 | * |
||
295 | * @return boolean |
||
296 | */ |
||
297 | public function canProcessRequest() |
||
301 | |||
302 | /** |
||
303 | * Process the uploaded files into the HTTP request |
||
304 | * |
||
305 | * @return boolean |
||
306 | */ |
||
307 | public function processRequest() |
||
344 | } |
||
345 |