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');
+ try {
+ $img = @$_FILES['upload'];
+ if (!$img or $img['error'] !== UPLOAD_ERR_OK)
+ throw new Exception('bestand niet goed ontvangen: '.$img['error']);
- $datadir = 'data/' . date('Y');
- $target = $datadir.'/'.$img['name'];
- move_uploaded_file($img['tmp_name'], $target);
+ $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');
+ }
+ }
+ catch (Exception $e) {
+ abort($e->getMessage(), '409 upload error');
+ }
switch (@$_GET['output']) {
case 'ckescript':