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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sthomas at townnews dot com
New email:
PHP Version: OS:

 

 [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: Mon Apr 29 23:01:28 2024 UTC