pupupu

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

commit
6929c050772c51ed8f538ff13f8f8804b4dcbca2
parent
994da5670fcc81b7353a574480cb4326b5371315
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2018-10-19 09:52
allow to handle upload subdirs

Diffstat

M index.php 24 +++++++++++++-----------

1 files changed, 13 insertions, 11 deletions


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

@@ -176,18 +176,18 @@ class Pupupu
  176   176         return $this->targetUrl . $path . '/';
  177   177     }
  178   178 
  179    -1     public function upload($file)
   -1   179     public function upload($path, $file)
  180   180     {
  181    -1         $p = $this->targetDir . '/files/' . $file['name'];
   -1   181         $p = $this->targetDir . '/files' . $path . '/' . $file['name'];
  182   182         mkdirp(dirname($p));
  183   183         move_uploaded_file($file['tmp_name'], $p);
  184   184     }
  185   185 
  186    -1     public function getUploads()
   -1   186     public function getUploads($path)
  187   187     {
  188   188         $uploads = array();
  189    -1         $p = $this->targetDir . '/files';
  190    -1         $u = $this->targetUrl . '/files';
   -1   189         $p = $this->targetDir . '/files' . $path;
   -1   190         $u = $this->targetUrl . '/files' . $path;
  191   191         foreach (scandir($p) as $name) {
  192   192             if (is_file("$p/$name")) {
  193   193                 $uploads[$name] = "$u/$name";
@@ -196,9 +196,9 @@ class Pupupu
  196   196         return $uploads;
  197   197     }
  198   198 
  199    -1     public function rmUpload($name)
   -1   199     public function rmUpload($path)
  200   200     {
  201    -1         unlink($this->targetDir . '/files/' . $name);
   -1   201         unlink($this->targetDir . '/files' . $path);
  202   202     }
  203   203 
  204   204     public function render($path, $verbose=false)
@@ -259,15 +259,17 @@ function ensureTrailingSlash()
  259   259 
  260   260 function uploadView($pupupu, $twig)
  261   261 {
   -1   262     $path = validatePath(substr($_GET['path'], 8));
   -1   263 
  262   264     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
  263   265         echo $twig->render('uploads.html', array(
  264    -1             'files' => $pupupu->getUploads(),
   -1   266             'files' => $pupupu->getUploads($path),
  265   267         ));
  266   268     } elseif (isset($_FILES['file'])) {
  267    -1         $pupupu->upload($_FILES['file']);
   -1   269         $pupupu->upload($path, $_FILES['file']);
  268   270         header("Location: ", true, 302);
  269   271     } else {
  270    -1         $pupupu->rmUpload($_POST['name']);
   -1   272         $pupupu->rmUpload($path . '/' . $_POST['name']);
  271   273         header("Location: ", true, 302);
  272   274     }
  273   275 }
@@ -334,7 +336,7 @@ if (isset($_SERVER['REQUEST_METHOD'])) {
  334   336         header('Location: ?path=', true, 302);
  335   337     } elseif ($_GET['path'] === '_site') {
  336   338         siteView($pupupu, $twig);
  337    -1     } elseif ($_GET['path'] === '_uploads') {
   -1   339     } elseif (substr($_GET['path'], 0, 8) === '_uploads') {
  338   340         uploadView($pupupu, $twig);
  339   341     } else {
  340   342         pageView($pupupu, $twig);