Add download single note

This commit is contained in:
quenousimporte 2024-10-02 11:49:15 +02:00
parent 53d3516b04
commit 630ac914b0
2 changed files with 20 additions and 8 deletions

View File

@ -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';
}

View File

@ -5,7 +5,8 @@
<input type="submit" name="preview" value="preview" accesskey="p" formtarget="_blank">
<input type="submit" name="links" value="links" accesskey="l">
<input type="submit" name="stats" value="stats" accesskey="i">
<input type="submit" name="delete" value="delete" accesskey="d">
<input type="submit" name="download" value="download" accesskey="d">
<input type="submit" name="delete" value="delete">
<input hidden name="lastchanged" value="<? echo $lastchanged; ?>">
<?php
if (isset($_POST['stats']))