first version

This commit is contained in:
Bastian Allgeier
2019-01-13 23:17:34 +01:00
commit 01277f79f2
595 changed files with 82913 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
<?php
namespace Kirby\Http\Request;
/**
* The Files object sanitizes
* the input coming from the $_FILES
* global. Especially for multiple uploads
* for the same key, it will produce a more
* usable array.
*
* @package Kirby Http
* @author Bastian Allgeier <bastian@getkirby.com>
* @link http://getkirby.com
* @copyright Bastian Allgeier
* @license MIT
*/
class Files
{
use Data;
/**
* Sanitized array of all received files
*
* @var array
*/
protected $files;
/**
* Creates a new Files object
* Pass your own array to mock
* uploads.
*
* @param array|null $files
*/
public function __construct($files = null)
{
if ($files === null) {
$files = $_FILES;
}
$this->files = [];
foreach ($files as $key => $file) {
if (is_array($file['name'])) {
foreach ($file['name'] as $i => $name) {
$this->files[$key][] = [
'name' => $file['name'][$i] ?? null,
'type' => $file['type'][$i] ?? null,
'tmp_name' => $file['tmp_name'][$i] ?? null,
'error' => $file['error'][$i] ?? null,
'size' => $file['size'][$i] ?? null,
];
}
} else {
$this->files[$key] = $file;
}
}
}
/**
* The data method returns the files
* array. This is only needed to make
* the Data trait work for the Files::get($key)
* method.
*
* @return array
*/
public function data(): array
{
return $this->files;
}
}