|
8 | 8 | * License: GNU/GPLv2
|
9 | 9 | * @see LICENSE.txt
|
10 | 10 | *
|
11 |
| - * This file: Upload handler (last modified: 2020.07.13). |
| 11 | + * This file: Upload handler (last modified: 2020.07.16). |
12 | 12 | */
|
13 | 13 |
|
14 | 14 | namespace phpMussel\Web;
|
@@ -146,13 +146,13 @@ public function scan()
|
146 | 146 | $FilesToScan = [];
|
147 | 147 |
|
148 | 148 | /** Iterate through $_FILES array and scan as necessary. */
|
149 |
| - foreach ($_FILES as $FileKey => $FileData) { |
| 149 | + foreach ($_FILES as $FileData) { |
150 | 150 | /** Guard. */
|
151 | 151 | if (!isset($FileData['error'])) {
|
152 | 152 | continue;
|
153 | 153 | }
|
154 | 154 |
|
155 |
| - /** Normalise the structure of the uploads array. */ |
| 155 | + /** Normalise the structure of the files array. */ |
156 | 156 | if (!is_array($FileData['error'])) {
|
157 | 157 | $FilesData['FileSet'] = [
|
158 | 158 | 'name' => [$FileData['name']],
|
@@ -263,7 +263,7 @@ public function scan()
|
263 | 263 | }
|
264 | 264 |
|
265 | 265 | /** Exit here if there aren't any file upload detections. */
|
266 |
| - if (count($this->Loader->ScanResultsText) < 1) { |
| 266 | + if (empty($this->Loader->InstanceCache['DetectionsCount'])) { |
267 | 267 | return;
|
268 | 268 | }
|
269 | 269 |
|
@@ -399,4 +399,43 @@ public function scan()
|
399 | 399 | /** Send HTML output and the kill the script. */
|
400 | 400 | die($Output);
|
401 | 401 | }
|
| 402 | + |
| 403 | + /** |
| 404 | + * A method provided for running the names of uploaded files through the |
| 405 | + * demojibakefier for the optional use of the implementation (warning: this |
| 406 | + * will modify the "name" value of the entries in $_FILES). |
| 407 | + * |
| 408 | + * @param string $Encoding The implementation may optionally specify the |
| 409 | + * preferred encoding for the demojibakefier to normalise names to. It |
| 410 | + * is generally recommended to leave it at its default, however. |
| 411 | + */ |
| 412 | + public function demojibakefier(string $Encoding = 'UTF-8') |
| 413 | + { |
| 414 | + /** Instantiate the demojibakefier class. */ |
| 415 | + $Demojibakefier = new \Maikuolan\Common\Demojibakefier($Encoding); |
| 416 | + |
| 417 | + /** Exit early if there isn't anything to run through. */ |
| 418 | + if (!$this->Uploads) { |
| 419 | + return; |
| 420 | + } |
| 421 | + |
| 422 | + /** Iterate through the $_FILES array. */ |
| 423 | + foreach ($_FILES as &$FileData) { |
| 424 | + /** Guard. */ |
| 425 | + if (!isset($FileData['name'])) { |
| 426 | + continue; |
| 427 | + } |
| 428 | + |
| 429 | + /** Run the names through the demojibakefier. */ |
| 430 | + if (is_array($FileData['name'])) { |
| 431 | + foreach ($FileData['name'] as &$FileName) { |
| 432 | + if (is_string($FileName)) { |
| 433 | + $FileName = $Demojibakefier->guard($FileName); |
| 434 | + } |
| 435 | + } |
| 436 | + } elseif (is_string($FileData['name'])) { |
| 437 | + $FileData['name'] = $Demojibakefier->guard($FileData['name']); |
| 438 | + } |
| 439 | + } |
| 440 | + } |
402 | 441 | }
|
0 commit comments