0

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
********************** 
0

2 Answers 2

3

have you tried:

$name_val = $x->files[0]->name;
Sign up to request clarification or add additional context in comments.

3 Comments

Think it might be $x["files"][0]->name ... top level element appears to be an array
what is generating $x in the first place? can you provide more context?
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
0
$_FILES['files']['error'];
$_FILES['files']['name'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.