From ab3ebc53acde6f060649a01403a886f5485f7bf6 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 11 Jul 2018 21:09:21 +0200 Subject: [PATCH] login/edit: move upload handling code into include --- login/edit.php | 22 +++++++--------------- upload.inc.php | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 upload.inc.php diff --git a/login/edit.php b/login/edit.php index 15b0a2a..101244a 100644 --- a/login/edit.php +++ b/login/edit.php @@ -123,27 +123,19 @@ if ($_POST) { if (!isset($cols[$col]) and @$cols[$col]['type'] == 'file') { continue; # unknown } - switch ($val['error']) { - case UPLOAD_ERR_OK: - break; - case UPLOAD_ERR_NO_FILE: - continue 2; # current - default: - $colwarn[$col] = "Afbeelding niet goed ontvangen."; - continue 2; - } if (empty($cols[$col]['target'])) { $colwarn[$col] = "Kan niet worden aangepast."; continue; } - if (!@move_uploaded_file($val['tmp_name'], $cols[$col]['target'])) { - $colwarn[$col] = "Fout bij opslaan."; + try { + require_once('upload.inc.php'); + $target = userupload($val, $cols[$col]['target']); + if (!$target) continue; + $cols[$col]['value'] = ''; } - foreach (@glob('thumb/*/') as $thumbres) { - # attempt to remove old derivations - @unlink($thumbres.'/'.$cols[$col]['target']); + catch (Exception $e) { + $colwarn[$col] = $e->getMessage(); } - $cols[$col]['value'] = ''; } if (!empty($_POST['newpass'])) { diff --git a/upload.inc.php b/upload.inc.php new file mode 100644 index 0000000..aa24558 --- /dev/null +++ b/upload.inc.php @@ -0,0 +1,21 @@ +