From: Mischa POSLAWSKY Date: Thu, 14 Jun 2018 16:43:22 +0000 (+0200) Subject: edit: catch upload errors X-Git-Tag: v3.1~6 X-Git-Url: http://git.shiar.net/minimedit.git/commitdiff_plain/028bc424ac17a0e6c9f1c50149b9214dce27cd04 edit: catch upload errors Prepare for messages to be included in response. --- 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']) {