I'm implementing a multi purpose html form posting code in PHP having able to post object graph structures.
So I created some naming rules and based on them, I parse indexes in the server side.
One of those rules is something like this:
<input name="myModels[children[0]]" type="text" />
Of course above naming is a little shortened to make it easy to get to the point.
That naming is working perfectly when I retrieved them from
$_POST
but when I use it in file inputs, they never appear in $_FILE global array and
print_r($_FILES);
is empty
According to file upload php manual
PHP supports HTML array feature even with files.
So why is that? Why that type of naming ([] inside []) works for POSTED data but does not for file data.
Please note that its not a problem with uploading file itself.
Uploading is working grate even with arrays. Even with arrays with key indexes.
The one I'm trying to figure out is:
<form action="/Test/uploadTest.php" method="post" enctype="multipart/form-data" >
File1 <input name="myModels[postedFiles[0]]" type="file" /></br>
File2 <input name="myModels[postedFiles[1]]" type="file" /></br>
<input type="submit" value="post" />
</form>
And at the server in uploadTest.php
print_r($_FILES);
Is empty.
My PHP version is a little old and it is PHP 5.3.6-13. Do you think its something about my PHP version or its some sort of a bug even in newer versions of PHP?
Thanks in advance.
Solution: Both the answers provided by @tozer83 and @alvaro were very helpful. Now that it turns out multipart forms are some sort of different in handling non scalar indexes and trying to get advantages of html arrays with file inputs in order to create an expression for creating Complex Object Graphs just like the other frameworks in other languages is not going to work in PHP. One should ignore html arrays or use other literals like parentheses to work around this. It is sort of hard to decide which ones check mark should be clicked! Considering this high rank that @alvoro already got, I decided to choose @tozer83's answer because he answered first and gave a solution. But @alvaro's answer was detailed and very helpful too. So I +1 his answer.
myModels[postedFiles][0]by chance?