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()];
}
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()).'.';
}
}
<?php
-function userupload($input, $target)
+function userupload($input, $target = NULL, $filename = NULL)
{
switch ($input['error']) {
case UPLOAD_ERR_OK:
case UPLOAD_ERR_NO_FILE:
return; # current
default:
- throw new Exception("Afbeelding niet goed ontvangen.");
+ throw new Exception('bestand niet goed ontvangen: '.$input['error']);
}
+
+ if (isset($target)) {
+ if (!file_exists($target) and !@mkdir($target, 0777, TRUE)) {
+ throw new Exception("bestand kon niet geplaatst worden in $target");
+ }
+ $target .= '/';
+ }
+ if (isset($filename)) {
+ $target .= $filename;
+ }
+ else {
+ $target .= $input['name'];
+ }
+
if (!@move_uploaded_file($input['tmp_name'], $target)) {
- throw new Exception("Fout bij opslaan.");
+ throw new Exception('bestand kon niet worden opgeslagen');
}
foreach (@glob('thumb/*/') as $thumbres) {