allow modify pad by posting raw data

with this changes, we could create/modify pad like below
```bash
curl phus.lu/notes/z -d 'hello,

welcome to my pad!
'
```
This commit is contained in:
phuslu 2023-10-09 14:23:59 +08:00 committed by GitHub
parent 071d5b9fc9
commit fb0f2ea912
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -20,13 +20,13 @@ if (!isset($_GET['note']) || strlen($_GET['note']) > 64 || !preg_match('/^[a-zA-
$path = $save_path . '/' . $_GET['note'];
if (isset($_POST['text'])) {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$text = isset($_POST['text']) ? $_POST['text'] : file_get_contents("php://input");
// Update file.
file_put_contents($path, $_POST['text']);
file_put_contents($path, $text);
// If provided input is empty, delete file.
if (!strlen($_POST['text'])) {
if (!strlen($text)) {
unlink($path);
}
die;