php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20402 _FILES unintuitive when arrays used.
Submitted: 2002-11-12 15:04 UTC Modified: 2002-11-12 17:01 UTC
From: sthomas at townnews dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.2.3 OS: Redhat 7.3
Private report: No CVE-ID: None
 [2002-11-12 15:04 UTC] sthomas at townnews dot com
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 -------------------

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-12 17:01 UTC] sniper@php.net
This is not gonna change. And it's not bug.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 09:01:32 2024 UTC