|
Posted by Arshavir Grigorian on 05/17/05 00:12
mayo wrote:
> I'm having a little problem adding to an array. Each time I add to an
> array it wipes what was previously added. I'm using array_push().
>
> $items=array();
> $items=array_push($items, $_POST["whatever"]);
>
> I'm missing something easy.
>
> thx
>
>
I am having a similar problem:
if (! move_uploaded_file($_FILES['userfile']['tmp_name'], $image_file)) {
$message = "Problem uploading the file: $image_file";
} else {
$image_data = array ( "path" => $image_file,
"type" => $_FILE['userfile']['type']);
if (! is_array($_SESSION['image_data'])) {
$_SESSION['image_data'] = array($image_data);
} else {
array_push ($_SESSION['image_data'], $image_data);
}
}
Somehow, when I check the contents of $image_data, I get the expected
two items + a "0 - Array" entry. I have no idea what it is or where it
gets set.
Additionally, when I print out the contents of $_SESSION['image_data'] via:
foreach ($_SESSION['image_data'] as $image_datum) {
if (is_array($image_datum)) {
foreach ($image_datum as $key => $value) {
echo "array: ".$key."-".$value."\n";
}
} else {
echo "data: ".$image_datum."\n";
}
}
I get:
* data: tmp/image_dcaa588e5da9fa009e369b5715d0c1b0_23
* data: image/gif
* array: path-tmp/image_dcaa588e5da9fa009e369b5715d0c1b0_23
* array: type-image/gif
And, if the above initialization code is executed multiple times, the
contents of $_SESSION['image_data'] are completely wiped and
reinitialized instead instead of accumulating (array_push()).
Any help would be much appreciated.
--
Arshavir Grigorian
Systems Administrator/Engineer
Navigation:
[Reply to this message]
|