Reputation: 27
I want to show json object as var i'm trying to upload files on anonfiles using api but after uploading file it shows result in json format. so i want get particular object inside json here is my code.
if (isset($_POST['submit'])) {
$url = sprintf('https://api.anonfiles.com/upload', $token);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'file' => curl_file_create(
$_FILES['file']['tmp_name'],
$_FILES['file']['type'],
$_FILES['file']['name']
),
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$json = curl_exec($ch);
curl_close($ch);
$result = json_decode($json);
if (is_object($result) && $result->status) {
echo $json;
Upvotes: 1
Views: 80
Reputation: 326
If you want to access a particular object inside JSON, you are already doing it with the $result->status
.
After you json_decode
your JSON data, simply use $result->[the JSON NODE]
to which data that you require.
Upvotes: 2