I didn't know it returned an array(I've never used it), however it may not have that key. Make sure you first check to make sure its an array and that that array key exists.
you should use this
foreach($data as $name => $value)
echo $name . ": " . $value;
It will show
upload : o
Add the above code to yours(above your foreach loop) and I guarantee it will output the first character of each value and not the full value that your seeking. The whole point of the foreach loop is to iterate through the array without having to use a regular for loop
and the whole string counting bit. the $value variable is the data that the $name key holds, i.e if you added the below:
$array[$name] = $value;
to your code in that foreach loop(either one) you'd make a duplicate array with the same key-value pairing as the original name $array.
the testing for if its an array in a foreach loop is not needed. You already hard coded it as an array so testing for it to be one is ridiculous, because you already know its an array. If anything you should have tested before hand if its an array because that function will be called every iteration and consume unneeded memory. Php allows for char level variable output and thats why what your doing in the foreach loop is wrong and poor coding in general. Don't take my word though, output that data during iteration and see for yourself the values it gives you.
As far as getting content types, well you'll need to probably use regex to get all the data after the .(because some formats use 4 characters for their extension instead of 3) or substr(). Compare that value to predefined values and return the appropriate content type.