From 862d91755026431efbf621e3da7107f26ba221ed Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 11 Jul 2018 21:12:12 +0200 Subject: [PATCH] edit: implement filename storage in upload include --- edit/index.php | 20 ++++++-------------- login/edit.php | 4 ++-- upload.inc.php | 20 +++++++++++++++++--- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/edit/index.php b/edit/index.php index 6f4dc4d..cd22216 100644 --- a/edit/index.php +++ b/edit/index.php @@ -7,23 +7,15 @@ if (empty($User['admin'])) if ($_FILES) { $response = ['uploaded' => 0]; try { - $img = @$_FILES['upload']; - $response['fileName'] = $img['name']; - if (!$img or $img['error'] !== UPLOAD_ERR_OK) - throw new Exception('bestand niet goed ontvangen: '.$img['error']); - + require_once('upload.inc.php'); $datadir = implode('/', ['data', date('Y')]); if ($Args) $datadir .= $Args; - if (!file_exists($datadir) and !@mkdir($datadir, 0777, TRUE)) { - throw new Exception("bestand kon niet geplaatst worden in $datadir"); - } - - $target = $datadir.'/'.$img['name']; - $response['url'] = str_replace('%2F', '/', urlencode($target)); - if (!@move_uploaded_file($img['tmp_name'], $target)) { - throw new Exception('bestand kon niet worden opgeslagen'); + $target = userupload(@$_FILES['upload'], $datadir); + if ($target) { + $response['fileName'] = $_FILES['upload']['name']; + $response['url'] = str_replace('%2F', '/', urlencode($target)); + $response['uploaded']++; } - $response['uploaded']++; } catch (Exception $e) { $response['error'] = ['message' => $e->getMessage()]; diff --git a/login/edit.php b/login/edit.php index 101244a..ad9dbda 100644 --- a/login/edit.php +++ b/login/edit.php @@ -129,12 +129,12 @@ if ($_POST) { } try { require_once('upload.inc.php'); - $target = userupload($val, $cols[$col]['target']); + $target = userupload($val, NULL, $cols[$col]['target']); if (!$target) continue; $cols[$col]['value'] = ''; } catch (Exception $e) { - $colwarn[$col] = $e->getMessage(); + $colwarn[$col] = ucfirst($e->getMessage()).'.'; } } diff --git a/upload.inc.php b/upload.inc.php index aa24558..f1018c2 100644 --- a/upload.inc.php +++ b/upload.inc.php @@ -1,5 +1,5 @@