note 118390 added to features.file-upload.multiple

From: Date: Sat, 28 Nov 2015 11:17:09 +0000
Subject: note 118390 added to features.file-upload.multiple
Groups: php.notes 
Request: Send a blank email to php-notes+get-204237@lists.php.net to get a copy of this message
This is just a modification of the code which is the top note by "phpuser" here. His/her version requires that the $file_post array passed in to the function was created by a form submitted with the multiple attribute set. With multiple set in the html input tag, $_FILES["fileInputName"]["name"] is an array no matter if only one file is sent or multiple. But when <input type="file"> is used without the multiple attribute then $_FILES["fileInputName"]["name"] is not an array, it contains the the string with the filename. To use this neat function with or without multiple set and to get back an array which you can "foreach" over in either case, use this modification: function reArrayFiles(&$file_post) { $file_ary = array(); $multiple = is_array($file_post['name']); $file_count = $multiple ? count($file_post['name']) : 1; $file_keys = array_keys($file_post); for ($i=0; $i<$file_count; $i++) { foreach ($file_keys as $key) { $file_ary[$i][$key] = $multiple ? $file_post[$key][$i] : $file_post[$key]; } } return $file_ary; } ---- Server IP: 72.52.91.14 Probable Submitter: 213.66.225.189 ---- Manual Page -- http://php.net/manual/en/features.file-upload.multiple.php Edit -- https://master.php.net/note/edit/118390 Del: integrated -- https://master.php.net/note/delete/118390/integrated Del: useless -- https://master.php.net/note/delete/118390/useless Del: bad code -- https://master.php.net/note/delete/118390/bad+code Del: spam -- https://master.php.net/note/delete/118390/spam Del: non-english -- https://master.php.net/note/delete/118390/non-english Del: in docs -- https://master.php.net/note/delete/118390/in+docs Del: other reasons-- https://master.php.net/note/delete/118390 Reject -- https://master.php.net/note/reject/118390 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204237) next »