note 79894 deleted from features.file-upload by bjori
| From: | bjori@php.net | Date: | Fri, 21 Dec 2007 17:13:43 +0000 |
| Subject: | note 79894 deleted from features.file-upload by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133862@lists.php.net to get a copy of this message | ||
Note Submitter: thomas at thoftware dot de
----
As mentioned before, the way you can get information about uploaded files isn't very helpful
sometimes, especially if you are using variablenames creating arrays like "<input
name="foo[b][a][r]" type="file">". The following code takes all
information located in $_FILES and moves it into the appropriate variable (in the upper case,
$foo['b']['a']['r'] will contain all information about the uploaded
file, a very intuitive solution as I think). You may want to apply the code not only on $GLOBALS but
on $_POST too (or maybe only on the latter one), depending on how you access the variables submitted
by a posted formular.
Said enough, here is the code:
# check all information about uploaded files:
foreach ($_FILES as $idx => $val) {
# set pointer on variable in $GLOBALS:
$var =& $GLOBALS[$idx];
# check all information about file connected with variable:
foreach ($val as $typ => $val) {
# set pointer on variable in $GLOBALS:
$ptr =& $var;
# there are more array-keys:
while (is_array($val)) {
# set pointer on next key:
$ptr =& $ptr[key($val)];
# read value resp. next array-key:
$val = reset($val);
}
# collect value with original key in variable:
$ptr[$typ] = $val;
}
}
Works with PHP4, comments are very welcome.