Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

How to Write JSON to File in PHP

$data = array(
    'image' => $image_url,
    'mood' => $image_mood,
    'date' => $image_date
);

$data_array = file_get_contents($file_path);
$data_element = json_decode($data_array, true);
$data_element[] = $data;
$new_data = json_encode($data_element, JSON_PRETTY_PRINT);

if (!file_put_contents($file_path, $new_data)) {
    echo "success";
} else {
    echo "fail";
}
Source by github.com #
 
PREVIOUS NEXT
Tagged: #How #Write #JSON #File #PHP
ADD COMMENT
Topic
Name
5+1 =