I call the upload function and it returns a variable. when I do var_dump($x) it shows the following:
{"files":[{"name":"1004046_469695273124093_104592888_n_1_28860.jpg","size":0,"type":"image\/jpeg","error":"abort","delete_url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/?file=1004046_469695273124093_104592888_n_1_28860.jpg","delete_type":"DELETE"}]}array(1) {
["files"]=>
array(1) {
[0]=> object(stdClass)#24 (6) {
["name"]=> string(47) "1004046_469695273124093_104592888_n_1_28860.jpg"
["size"]=> int(0)
["type"]=> string(10) "image/jpeg"
["error"]=> string(5) "abort"
["delete_url"]=> string(104) "http://www.xxx.com/upload/uploader/server/php/?file=1004046_469695273124093_104592888_n_1_28860.jpg"
["delete_type"]=> string(6) "DELETE"
}
}
}
I tried var_dump(json_decode($x)) and the result is NULL.
My question is how do I get the value name from this???
tried these two:
echo $x->files[0]->name;
echo " ********************** ";
echo $x['files'][0]->name;
echo " ********************** ";
and the result is
{"files":[{"name":"1004046_469695273124093_104592888_n_1_14299.jpg","size":78289,"type":"image\/jpeg","url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/files\/1004046_469695273124093_104592888_n_1_14299.jpg","thumbnail_url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/files\/thumbnail\/1004046_469695273124093_104592888_n_1_14299.jpg","delete_url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/?file=1004046_469695273124093_104592888_n_1_14299.jpg","delete_type":"DELETE"}]}{"files":[{"name":"1004046_469695273124093_104592888_n_1_12920.jpg","size":0,"type":"image\/jpeg","error":"abort","delete_url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/?file=1004046_469695273124093_104592888_n_1_12920.jpg","delete_type":"DELETE"}]}
**********************
{"files":[{"name":"1004046_469695273124093_104592888_n_1_15697.jpg","size":0,"type":"image\/jpeg","error":"abort","delete_url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/?file=1004046_469695273124093_104592888_n_1_15697.jpg","delete_type":"DELETE"}]}1004046_469695273124093_104592888_n_1_15697.jpg
**********************
2 Answers 2
have you tried:
$name_val = $x->files[0]->name;
Sign up to request clarification or add additional context in comments.
3 Comments
Orangepill
Think it might be $x["files"][0]->name ... top level element appears to be an array
Nathan
what is generating $x in the first place? can you provide more context?
Kal
there is a string before the first array. I did json_decode the split it by } then I treated the right hand side as an array `$x['files'][0]->name gave me the result
$_FILES['files']['error'];
$_FILES['files']['name'];
answered Jun 19, 2013 at 1:54
user2417483
Comments
lang-php