login/edit: move upload handling code into include
[minimedit.git] / upload.inc.php
1 <?php
2 function userupload($input, $target)
3 {
4         switch ($input['error']) {
5         case UPLOAD_ERR_OK:
6                 break;
7         case UPLOAD_ERR_NO_FILE:
8                 return; # current
9         default:
10                 throw new Exception("Afbeelding niet goed ontvangen.");
11         }
12         if (!@move_uploaded_file($input['tmp_name'], $target)) {
13                 throw new Exception("Fout bij opslaan.");
14         }
15
16         foreach (@glob('thumb/*/') as $thumbres) {
17                 # attempt to remove old derivations
18                 @unlink($thumbres . '/' . $target);
19         }
20         return $target;
21 }