fix: add list to quicknote and quickupload

This commit is contained in:
Matthieu Bessat 2021-08-08 20:54:01 +02:00
parent abd4773e16
commit 51d27c6f1c
4 changed files with 56 additions and 18 deletions

View file

@ -1,23 +1,5 @@
<?php <?php
function getFilesAsArray($path) {
$dirs = array_filter(glob($path . '/*'), 'is_file');
$dirs = array_map(function ($dirName) {
$compo = explode('/', $dirName);
return $compo[count($compo)-1];
}, $dirs);
return array_values($dirs);
}
function getDirsAsArray($path) {
$dirs = array_filter(glob($path . '/*'), 'is_dir');
$dirs = array_map(function ($dirName) {
$compo = explode('/', $dirName);
return $compo[count($compo)-1];
}, $dirs);
return array_values($dirs);
}
header('Content-Type: application/json'); header('Content-Type: application/json');
$logAt = __DIR__ . '/../../tmp/requests'; $logAt = __DIR__ . '/../../tmp/requests';

View file

@ -5,9 +5,30 @@ $path = __DIR__ . '/../../tmp/quicknotes';
if (!file_exists($path)) { if (!file_exists($path)) {
mkdir($path); mkdir($path);
} }
if (!file_exists($path . '/logs.txt')) {
file_put_contents($path . '/logs.txt', '');
}
$path = realpath($path); $path = realpath($path);
if ($_SERVER['REQUEST_URI'] === '/list') {
$msgs = explode("\n", file_get_contents($path . '/logs.txt'));
array_pop($msgs);
?>
<h3>List of messages</h3>
<ul>
<?php
foreach ($msgs as $msg) {
?>
<li><?= $msg ?></li>
<?php
}
?>
</ul>
<?php
exit();
}
$message = ''; $message = '';
if (isset($_GET['m'])) { if (isset($_GET['m'])) {

View file

@ -11,6 +11,23 @@ function slugify($string){
return strtolower(trim(preg_replace('/[^.A-Za-z0-9-]+/', '-', $string), '-')); return strtolower(trim(preg_replace('/[^.A-Za-z0-9-]+/', '-', $string), '-'));
} }
if ($_SERVER['REQUEST_URI'] === '/list') {
$files = getFilesAsArray($path);
?>
<h3>List of uploaded files</h3>
<ul>
<?php
foreach ($files as $fileName) {
?>
<li><a href="/file/<?= $fileName ?>"><?= $fileName ?></a></li>
<?php
}
?>
</ul>
<?php
exit();
}
if (isset($_FILES['file'])) { if (isset($_FILES['file'])) {
$f = $_FILES['file']; $f = $_FILES['file'];
copy($f['tmp_name'], $path . '/' . uniqid() . '_' . slugify($f['name'])); copy($f['tmp_name'], $path . '/' . uniqid() . '_' . slugify($f['name']));

View file

@ -36,3 +36,21 @@ function resumeRequest() {
'at_unix_micro' => microtime() 'at_unix_micro' => microtime()
]; ];
} }
function getFilesAsArray($path) {
$dirs = array_filter(glob($path . '/*'), 'is_file');
$dirs = array_map(function ($dirName) {
$compo = explode('/', $dirName);
return $compo[count($compo)-1];
}, $dirs);
return array_values($dirs);
}
function getDirsAsArray($path) {
$dirs = array_filter(glob($path . '/*'), 'is_dir');
$dirs = array_map(function ($dirName) {
$compo = explode('/', $dirName);
return $compo[count($compo)-1];
}, $dirs);
return array_values($dirs);
}