diff options
Diffstat (limited to '')
| -rw-r--r-- | app/class/globals.php | 15 | 
1 files changed, 15 insertions, 0 deletions
| diff --git a/app/class/globals.php b/app/class/globals.php index 8ac67e1..6e3b7fd 100644 --- a/app/class/globals.php +++ b/app/class/globals.php @@ -247,4 +247,19 @@ function saveFile(array $file, string $path, int $maxsize, ?array $allowedMime =      return true;  } +/* + * Similar to saveFile, but takes the uploaded file field name, + * rather than the array directly.  The file is looked up in + * $_FILES.  If it does not exist, an exception is thrown. + */ +function saveIfFile(string $file, string $path, int $maxsize, ?array $allowedMime = NULL, +    ?string &$origName = NULL, ?string &$origMime = NULL) : bool +{ +    if (!isset($_FILES[$file])) +        throw new Exception("Requested file upload, but no data was supplied"); + +    $f = $_FILES[$file]; +    return saveFile($f, $path, $maxsize, $allowedMime, $origName, $origMime); +} +  ?> | 
