From 028bc424ac17a0e6c9f1c50149b9214dce27cd04 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 14 Jun 2018 18:43:22 +0200 Subject: [PATCH] edit: catch upload errors Prepare for messages to be included in response. --- edit/index.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/edit/index.php b/edit/index.php index 2367b23..19c02d9 100644 --- a/edit/index.php +++ b/edit/index.php @@ -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']) { -- 2.30.0