/** * testNormalizeGlobalFilesArray * * @return void */ public function testNormalizeGlobalFilesArray() { $data = $_FILES = array('name' => array(0 => 'foo.txt', 1 => 'bar.txt'), 'type' => array(0 => 'text/plain', 1 => 'text/plain'), 'tmp_name' => array(0 => '/tmp/phpYzdqkD', 1 => '/tmp/phpeEwEWG'), 'error' => array(0 => 0, 1 => 0), 'size' => array(0 => 123, 1 => 456)); $expected = [0 => ['name' => 'foo.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/phpYzdqkD', 'error' => 0, 'size' => 123], 1 => ['name' => 'bar.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/phpeEwEWG', 'error' => 0, 'size' => 456]]; $data = array('name' => array(0 => 'foo.txt', 1 => 'bar.txt'), 'type' => array(0 => 'text/plain', 1 => 'text/plain'), 'tmp_name' => array(0 => '/tmp/phpYzdqkD', 1 => '/tmp/phpeEwEWG'), 'error' => array(0 => 0, 1 => 0), 'size' => array(0 => 123, 1 => 456)); $result = StorageUtils::normalizeGlobalFilesArray($data); $this->assertEquals($result, $expected); $result = StorageUtils::normalizeGlobalFilesArray(); $this->assertEquals($result, $expected); }
/** * Method to normalize the annoying inconsistency of the $_FILE array structure * * @link http://www.php.net/manual/en/features.file-upload.multiple.php#109437 * @param array $array * @return array Empty array if $_FILE is empty, if not normalize array of Filedata.{n} */ public static function normalizeGlobalFilesArray($array = null) { return StorageUtils::normalizeGlobalFilesArray($array); }