pupupu

simple static CMS for crappy servers
git clone https://git.ce9e.org/pupupu.git

commit
5d4c305198c8cd803009c1cf23cce9addc38b770
parent
3ca5c8d09ab1c5883ceec7e87efa95e46911ed96
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2018-10-13 21:48
add file upload

Diffstat

M index.php 16 ++++++++++++++++
M templates/base.html 1 +
A templates/uploads.html 20 ++++++++++++++++++++

3 files changed, 37 insertions, 0 deletions


diff --git a/index.php b/index.php

@@ -139,6 +139,22 @@ if (isset($_SERVER['REQUEST_METHOD'])) {
  139   139             renderAll();
  140   140             header("Location: ", true, 302);
  141   141         }
   -1   142     } elseif ($_GET['path'] === '_uploads') {
   -1   143         if ($_SERVER['REQUEST_METHOD'] == 'GET') {
   -1   144             echo $twig->render('uploads.html', array(
   -1   145                 'files' => array_filter(scandir('../uploads/'), function($file) {
   -1   146                     return is_file("../uploads/$file");
   -1   147                 }),
   -1   148             ));
   -1   149         } elseif (isset($_FILES['file'])) {
   -1   150             mkdirp('../uploads');
   -1   151             $f = $_FILES['file'];
   -1   152             move_uploaded_file($f['tmp_name'], '../uploads/' . $f['name']);
   -1   153             header("Location: ", true, 302);
   -1   154         } else {
   -1   155             unlink('../uploads/' . $_POST['file']);
   -1   156             header("Location: ", true, 302);
   -1   157         }
  142   158     } else {
  143   159         $path = validatePath($_GET['path']);
  144   160 

diff --git a/templates/base.html b/templates/base.html

@@ -16,6 +16,7 @@
   16    16         </nav>
   17    17         <nav>
   18    18             <a href="?path=_site">site config</a>
   -1    19             <a href="?path=_uploads">uploads</a>
   19    20         </nav>
   20    21     </header>
   21    22 

diff --git a/templates/uploads.html b/templates/uploads.html

@@ -0,0 +1,20 @@
   -1     1 {% extends 'base.html' %}
   -1     2 
   -1     3 {% block main %}
   -1     4     <ul>
   -1     5         {% for file in files %}
   -1     6             <li>
   -1     7                 <a href="/uploads/{{ file }}" target="_blank">{{ file }}</a>
   -1     8                 <form method="post">
   -1     9                     <input type="hidden" name="file" value="{{ file }}">
   -1    10                     <button class="button--danger">Delete</button>
   -1    11                 </form>
   -1    12             </li>
   -1    13         {% endfor %}
   -1    14     </ul>
   -1    15 
   -1    16     <form method="post" enctype="multipart/form-data">
   -1    17         <input type="file" name="file">
   -1    18         <input type="submit" value="Save">
   -1    19     </form>
   -1    20 {% endblock %}