-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.php
More file actions
89 lines (71 loc) · 1.68 KB
/
Copy pathnote.php
File metadata and controls
89 lines (71 loc) · 1.68 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['delete'])) {
$name = $_POST['name'];
if (file_exists("notes/$name.txt")) {
unlink("notes/$name.txt");
}
header('Location: index.php');
exit;
}
$name = trim($_POST['name']);
$author = trim($_POST['author']);
$content = $_POST['content'];
if ($name !== '') {
file_put_contents(
"notes/$name.txt",
$author . "\n" . $content
);
header('Location: note.php?file=' . urlencode($name));
exit;
}
}
$name = $_GET['file'] ?? '';
$author = '';
$content = '';
if ($name !== '' && file_exists("notes/$name.txt")) {
$lines = file("notes/$name.txt");
$author = trim($lines[0] ?? '');
$content = implode('', array_slice($lines, 1));
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Note: <?php echo htmlspecialchars($name); ?></title>
</head>
<body>
<form method="post">
<input
type="text"
name="name"
placeholder="note name"
value="<?php echo htmlspecialchars($name); ?>"
>
<input
type="text"
name="author"
placeholder="author"
value="<?php echo htmlspecialchars($author); ?>"
>
<br><br>
<textarea name="content" rows="20" cols="80"><?php
echo htmlspecialchars($content);
?></textarea>
<br><br>
<button type="submit">Save</button>
<button
type="submit"
name="delete"
value="1"
onclick="return confirm('Delete note?')"
>
Delete
</button>
</form>
<br>
<a href="index.php">Back</a>
</body>
</html>