From 630ac914b02044191c58481f76d1f114e397efe3 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Wed, 2 Oct 2024 11:49:15 +0200 Subject: [PATCH] Add download single note --- index.php | 25 ++++++++++++++++++------- note.php | 3 ++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/index.php b/index.php index 09505a9..f920f57 100644 --- a/index.php +++ b/index.php @@ -21,7 +21,15 @@ $_SESSION['index'] = array_map(fn($value): string => str_replace('.md', '', $value), $files); } - function download() + function downloadnote($path) + { + header('Content-disposition: attachment; filename=' . basename($path)); + header('Content-type: text/markdown'); + readfile($path); + exit; + } + + function downloadall() { $zip = new ZipArchive(); $zip_name = 'bbn.zip'; @@ -111,20 +119,19 @@ } $nextpage = 'home'; + $preview = ''; if (isset($_GET['download'])) { - download(); + downloadall(); } - - $preview = ''; - if (isset($_GET['clip']) && $_GET['param']) + else if (isset($_GET['clip']) && $_GET['param']) { $content = $_GET['param'] . "\r\n" . file_get_contents($dir . '/todo.md'); savenote('todo', $content); $_GET['param'] = ''; } - else if (isset($_POST['save']) || isset($_POST['home']) || isset($_POST['links']) || isset($_POST['stats'])) + else if (isset($_POST['save']) || isset($_POST['home']) || isset($_POST['links']) || isset($_POST['stats']) || isset($_POST['download'])) { $title = $_POST['title']; $content = $_POST['content']; @@ -137,7 +144,11 @@ removefromindex($previoustitle); } - if (!isset($_POST['home'])) + if (isset($_POST['download'])) + { + downloadnote($dir . '/' . $title . '.md'); + } + else if (!isset($_POST['home'])) { $nextpage = 'note'; } diff --git a/note.php b/note.php index 2900b07..81d8203 100644 --- a/note.php +++ b/note.php @@ -5,7 +5,8 @@ - + +