note 114596 added to reserved.variables.files

From: Date: Mon, 10 Mar 2014 16:29:38 +0000
Subject: note 114596 added to reserved.variables.files
Groups: php.notes 
Request: Send a blank email to php-notes+get-198852@lists.php.net to get a copy of this message
Here is my version of $_FILES rearrange. Unlike other codes here, this working well on any depth of $_FILES. <?php if (!empty($_FILES)) { function rearrange_files_array(array $array) { foreach ($array as &$value) { $_array = array(); foreach ($value as $prop => $propval) { if (is_array($propval)) { array_walk_recursive($propval, function(&$item, $key, $value) use($prop) { $item = array($prop => $item); }, $value); $_array = array_replace_recursive($_array, $propval); } else { $_array[$prop] = $propval; } } $value = $_array; } return $array; } echo '<pre>'.print_r(rearrange_files_array($_FILES), true).'</pre>'; } ?> <form method="post" enctype="multipart/form-data" style="clear: both;"> <h3>upload1</h3> <div><label>new0</label><input type="file" name="upload1[new][]" /></div> <div><label>new1</label><input type="file" name="upload1[new][]" /></div> <div><label>update.id11</label><input type="file" name="upload1[update][id11]" /></div> <div><label>update.id12</label><input type="file" name="upload1[update][id12]" /></div> <hr /> <h3>upload2</h3> <div><label>new0</label><input type="file" name="upload2[]" /></div> <div><label>new1</label><input type="file" name="upload2[]" /></div> <div><label>update.id21</label><input type="file" name="upload2[id21]" /></div> <div><label>update.id22</label><input type="file" name="upload2[id22]" /></div> <hr /> <div><label>upload3</label><input type="file" name="upload3" /></div> <input type="submit" value="go" /> </form> The output after empty form is posted: Array ( [upload1] => Array ( [new] => Array ( [0] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [1] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) [update] => Array ( [id11] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [id12] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) ) [upload2] => Array ( [0] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [1] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [id21] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [id22] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) [upload3] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) ---- Server IP: 72.52.91.14 Probable Submitter: 94.21.228.238 ---- Manual Page -- http://php.net/manual/en/reserved.variables.files.php Edit -- https://master.php.net/note/edit/114596 Del: integrated -- https://master.php.net/note/delete/114596/integrated Del: useless -- https://master.php.net/note/delete/114596/useless Del: bad code -- https://master.php.net/note/delete/114596/bad+code Del: spam -- https://master.php.net/note/delete/114596/spam Del: non-english -- https://master.php.net/note/delete/114596/non-english Del: in docs -- https://master.php.net/note/delete/114596/in+docs Del: other reasons-- https://master.php.net/note/delete/114596 Reject -- https://master.php.net/note/reject/114596 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198852) next »