forked from amitsin6h/html-canvas-screenshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_data.php
executable file
·35 lines (25 loc) · 912 Bytes
/
save_data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
if(isset($_POST['image'])){
if (file_exists('data.json')){
//if file exists open the file and append the data
$json_file = fopen("data.json", "a") or die("Unable to open file!");
$current_data = file_get_contents('data.json');
$array_data = json_decode($current_data, true);
$extra = array('imageURL' => $_POST['image'],);
$array_data[] = $extra;
$final_data = json_encode($array_data);
file_put_contents('data.json', $final_data);
fclose($json_file);
}else{
//create a json file and save the data in it
$json_file = fopen("data.json", "a") or die("Unable to open file!");
$current_data = file_get_contents('data.json');
$array_data = json_decode($current_data, true);
$extra = array('imageURL' => $_POST['image'],);
$array_data[] = $extra;
$final_data = json_encode($array_data);
file_put_contents('data.json', $final_data);
fclose($json_file);
}
}
?>