edit: catch upload errors
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 14 Jun 2018 16:43:22 +0000 (18:43 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 14 Jun 2018 16:43:22 +0000 (18:43 +0200)
Prepare for messages to be included in response.

edit/index.php

index 2367b2377e72834d52c8851cd54f4728fdcbed12..19c02d9698a670ee3363792a93aec73ebae67460 100644 (file)
@@ -5,18 +5,23 @@ if (empty($User['admin']))
        abort("geen beheersrechten", '401 unauthorised');
 
 if ($_FILES) {
-       $img = @$_FILES['upload'];
-       if (!$img or $img['error'] !== UPLOAD_ERR_OK)
-               abort('bestand niet goed ontvangen: '.$img['error'], '409 upload error');
-
-       $datadir = implode('/', ['data', date('Y')]);
-       if (!file_exists($datadir) and !@mkdir($datadir, 0777, TRUE)) {
-               abort("bestand kon niet geplaatst worden in $datadir", '409 upload error');
+       try {
+               $img = @$_FILES['upload'];
+               if (!$img or $img['error'] !== UPLOAD_ERR_OK)
+                       throw new Exception('bestand niet goed ontvangen: '.$img['error']);
+
+               $datadir = implode('/', ['data', date('Y')]);
+               if (!file_exists($datadir) and !@mkdir($datadir, 0777, TRUE)) {
+                       throw new Exception("bestand kon niet geplaatst worden in $datadir");
+               }
+
+               $target = $datadir.'/'.$img['name'];
+               if (!@move_uploaded_file($img['tmp_name'], $target)) {
+                       throw new Exception('bestand kon niet worden opgeslagen');
+               }
        }
-
-       $target = $datadir.'/'.$img['name'];
-       if (!@move_uploaded_file($img['tmp_name'], $target)) {
-               abort('bestand kon niet worden opgeslagen', '409 upload error');
+       catch (Exception $e) {
+               abort($e->getMessage(), '409 upload error');
        }
 
        switch (@$_GET['output']) {