note 116146 added to reserved.variables.files

From: Date: Fri, 14 Nov 2014 09:35:50 +0000
Subject: note 116146 added to reserved.variables.files
Groups: php.notes 
Request: Send a blank email to php-notes+get-200907@lists.php.net to get a copy of this message
This can be used to normalize $_FILES superglobal in cases when forms may contain multiple file inputs with array and non-array names: <?php function normalize_files_superglobal() { $result = array(); if (!is_array($_FILES) || !count($_FILES)) { return $result; } foreach ($_FILES as $input_name => $uploads) { $params = array_keys($uploads); foreach ($params as $key) { if (is_array($uploads[$key])) { foreach ($uploads[$key] as $index => $value) { $result[$input_name][$index][$key] = $value; } } else { $result[$input_name][0][$key] = $uploads[$key]; } } } return $result; } ?> BEFORE: array (size=2) 'upload1' => array (size=2) 'name' => string 'upload1.txt' (length=11) 'type' => string 'text/plain' (length=10) 'upload2' => array (size=2) 'name' => array (size=2) 0 => string 'upload2-1.txt' (length=13) 1 => string 'upload2-2.jpeg' (length=14) 'type' => array (size=2) 0 => string 'text/plain' (length=10) 1 => string 'image/jpeg' (length=10) AFTER: array (size=2) 'upload1' => array (size=1) 0 => array (size=2) 'name' => string 'upload1.txt' (length=11) 'type' => string 'text/plain' (length=10) 'upload2' => array (size=2) 0 => array (size=2) 'name' => string 'upload2-1.txt' (length=13) 'type' => string 'text/plain' (length=10) 1 => array (size=2) 'name' => string 'upload2-2.jpeg' (length=14) 'type' => string 'image/jpeg' (length=10) ---- Server IP: 72.52.91.14 Probable Submitter: 95.91.243.158 ---- Manual Page -- http://php.net/manual/en/reserved.variables.files.php Edit -- https://master.php.net/note/edit/116146 Del: integrated -- https://master.php.net/note/delete/116146/integrated Del: useless -- https://master.php.net/note/delete/116146/useless Del: bad code -- https://master.php.net/note/delete/116146/bad+code Del: spam -- https://master.php.net/note/delete/116146/spam Del: non-english -- https://master.php.net/note/delete/116146/non-english Del: in docs -- https://master.php.net/note/delete/116146/in+docs Del: other reasons-- https://master.php.net/note/delete/116146 Reject -- https://master.php.net/note/reject/116146 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200907) next »