note 96365 added to features.file-upload.multiple

From: Date: Tue, 23 Feb 2010 16:13:46 +0000
Subject: note 96365 added to features.file-upload.multiple
Groups: php.notes 
Request: Send a blank email to php-notes+get-166286@lists.php.net to get a copy of this message
After trying dozens of ways that are supposed to fix the wonkyness of the $_FILES array I didn't find any that could work with a input name like: userfile[christiaan][][][is][gaaf][] So I came up with this class <?php /** * A class that takes the pain out of the $_FILES array * @author Christiaan Baartse <christiaan@baartse.nl> */ class UploadedFiles extends ArrayObject { public function current() { return $this->_normalize(parent::current()); } public function offsetGet($offset) { return $this->_normalize(parent::offsetGet($offset)); } protected function _normalize($entry) { if(isset($entry['name']) && is_array($entry['name'])) { $files = array(); foreach($entry['name'] as $k => $name) { $files[$k] = array( 'name' => $name, 'tmp_name' => $entry['tmp_name'][$k], 'size' => $entry['size'][$k], 'type' => $entry['type'][$k], 'error' => $entry['error'][$k] ); } return new self($files); } return $entry; } } ?> This allows you to access a file uploaded using the following inputtype <input type="file" name="userfile[christiaan][][][is][gaaf][]" /> like <?php $files = new UploadedFiles($_FILES); var_dump($files['userfile']['christiaan'][0][0]['is']['gaaf'][0]); // or foreach($files['userfile']['christiaan'][0][0]['is']['gaaf'] as $file) { var_dump($file); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 91.197.72.16 ---- Manual Page -- http://www.php.net/manual/en/features.file-upload.multiple.php Edit -- https://master.php.net/note/edit/96365 Del: integrated -- https://master.php.net/note/delete/96365/integrated Del: useless -- https://master.php.net/note/delete/96365/useless Del: bad code -- https://master.php.net/note/delete/96365/bad+code Del: spam -- https://master.php.net/note/delete/96365/spam Del: non-english -- https://master.php.net/note/delete/96365/non-english Del: in docs -- https://master.php.net/note/delete/96365/in+docs Del: other reasons-- https://master.php.net/note/delete/96365 Reject -- https://master.php.net/note/reject/96365 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166286) next »