At work I've been dealing with some complex forms (publish pages of Symphony) that contain multiple image upload fields. I need a way to quickly merge $_FILES
with $_POST
, unfortunately you cannot simply merge the two with array_merge
because they don't follow the same structure.
Basically if you have $_POST[a][b]
it would be $_FILES[a][*][b]
. Replace *
with one of name
, type
, tmp_name
, error
or size
.
The content of the $_FILES
array as standard:
array
'image-a' => array
'name' => string '' (length=0)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0)
'error' => int 4
'size' => int 0
'image-b' => array
'name' => string '' (length=0)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0)
'error' => int 4
'size' => int 0
'image' => array
'name' => array
'sub' => array
'c' => string '' (length=0)
'type' => array
'sub' => array
'c' => string '' (length=0)
'tmp_name' => array
'sub' => array
'c' => string '' (length=0)
'error' => array
'sub' => array
'c' => int 4
'size' => array
'sub' => array
'c' => int 0
And the desired array after merging with $_POST
:
array
'MAX_FILE_SIZE' => string '5242880' (length=7)
'image-a' => array
'name' => string '' (length=0)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0)
'error' => int 4
'size' => int 0
'image-b' => array
'name' => string '' (length=0)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0)
'error' => int 4
'size' => int 0
'image' => array
'sub' => array
'c' => array
'name' => string '' (length=0)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0)
'error' => int 4
'size' => int 0