|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-11-12 17:01 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 14:00:01 2025 UTC |
PHP seems to mix up array-based file uploads. In the simple example code I've attached, pick any two files, and you'll get an array that looks like this: $_FILES = [thing]=> Array ( [name][test] => ... [type][test] => ... [tmp_name][test] => ... [error][test] => ... [size][test] => ... ) [other] => Array ( [name] => ... [type] => ... [tmp_name] => ... [error] => ... [size] => ... ) But you'd expect from how the last array works, that the elements: name, type, tmp_name, error, size, are associated with the actual uploaded file. In that case, you'd expect: [thing]=> Array ( [test] => Array ( [name] => ... [type] => ... [tmp_name] => ... [error] => ... [size] => ... ) ) [other] => Array ( [name] => ... [type] => ... [tmp_name] => ... [error] => ... [size] => ... ) This makes the $_FILES variable virtually impossible to use in a foreach or while context, as all of the associated elements are not associated with the array elements, but vice versa. This is also the crux of the problem that caused $_FILES to be removed from $_REQUEST in CVS. Since, if I have an element named stuff[name] in a form upload, and a file called stuff[thing], then the $_REQUEST variable would contain stuff[name][thing] when it should be stuff[thing][name] and stuff[name] as separate elements. ------------------- Attached Code ------------------- <form method="post" action="<?PHP print $_SERVER['PHP_SELF']; ?>" enctype="MULTIPART/FORM-DATA"> <input type="file" name="thing[test]"> <input type="file" name="other"> <input type="submit" value="Submit"> </form> <pre> <?PHP print_r($_FILES); ?> </pre> ------------------- Attached Code -------------------