note 89333 added to features.file-upload.multiple

From: Date: Tue, 03 Mar 2009 20:32:27 +0000
Subject: note 89333 added to features.file-upload.multiple
Groups: php.notes 
Request: Send a blank email to php-notes+get-151417@lists.php.net to get a copy of this message
If you try and upload files with multi-dimensional names like this: <input type="file" name="submission[screenshot]" /> <input type="file" name="other[dem][][img][]" /> You will get an unexpected format like this: <?php array( 'submission' => array ( 'name' => array( 'screenshot' => 'monster_wallpaper.jpg' ), 'type' => array( 'screenshot' => 'image/jpeg' ), 'tmp_name' => array( 'screenshot' => '/tmp/php48lX2Y' ), 'error' => array( 'screenshot' => 0 ), 'size' => array( 'screenshot' => 223262 ), ), .... ?> You can use the following function to re-format the array recursively in the usual format: <?php function format_files_array( $files, $name = null, &$new = false, $path = false ){ $names = array( 'name' => 'name', 'type' => 'type', 'tmp_name' => 'tmp_name', 'error' => 'error', 'size' => 'size' ); foreach( $files as $key => &$part ) { $key = ( string ) $key; if( in_array( $key, $names ) ) $name = $key; if( !in_array( $key, $names ) ) $path[] = $key; if( is_array( $part ) ) $part = format_files_array( $part, $name, $new, $path ); elseif( !is_array( $part ) ) { $current =& $new; foreach( $path as $p ) $current =& $current[$p]; $current[$name] = $part; unset( $path ); $name = null; } } return $new; } ?> ---- Server IP: 87.124.35.190 Probable Submitter: 86.151.179.191 ---- Manual Page -- http://www.php.net/manual/en/features.file-upload.multiple.php Edit -- https://master.php.net/note/edit/89333 Del: integrated -- https://master.php.net/note/delete/89333/integrated Del: useless -- https://master.php.net/note/delete/89333/useless Del: bad code -- https://master.php.net/note/delete/89333/bad+code Del: spam -- https://master.php.net/note/delete/89333/spam Del: non-english -- https://master.php.net/note/delete/89333/non-english Del: in docs -- https://master.php.net/note/delete/89333/in+docs Del: other reasons-- https://master.php.net/note/delete/89333 Reject -- https://master.php.net/note/reject/89333 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151417) next »