-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsavePost.php
More file actions
36 lines (30 loc) · 771 Bytes
/
savePost.php
File metadata and controls
36 lines (30 loc) · 771 Bytes
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
36
<?php
$my_file = fopen("./data/post.json", "a+");
$title = $_POST["title"];
$prize = $_POST["prize"];
$kg = $_POST["kg"];
$writing = $_POST["writing"];
$img = $_POST["img"];
$obj = '';
while(!feof($my_file)) {
$my_line = fgets($my_file);
if(json_decode($my_line) != ""){
$obj = json_decode($my_line);
}
}
$id = 0;
if ($obj != '') {
$id = ((int)(substr($obj->id, 1)) + 1);
}
$write = array();
$write["id"] = "w".$id;
$write["title"] = $title;
$write["prize"] = (int)$prize;
$write["kg"] = (int)$kg;
$write['img'] = $img;
fwrite($my_file, json_encode($write, JSON_UNESCAPED_UNICODE)."\n");
fclose($my_file);
$my_file = fopen("./data/post/w".$id.".txt", "a+");
fwrite($my_file, $writing);
fclose($my_file);
?>