nieuws: inline code to format article overviews
[minimedit.git] / upload.inc.php
1 <?php
2 function userupload($input, $target = NULL, $filename = NULL)
3 {
4         switch ($input['error']) {
5         case UPLOAD_ERR_OK:
6                 break;
7         case UPLOAD_ERR_INI_SIZE:
8         case UPLOAD_ERR_FORM_SIZE:
9                 throw new Exception('bestand te groot');
10                 break;
11         case UPLOAD_ERR_NO_FILE:
12                 return; # current
13         default:
14                 throw new Exception('bestand niet goed ontvangen: '.$input['error']);
15         }
16
17         if (isset($target)) {
18                 if (!file_exists($target) and !@mkdir($target, 0777, TRUE)) {
19                         throw new Exception("bestand kon niet geplaatst worden in $target");
20                 }
21                 $target .= '/';
22         }
23         if (isset($filename)) {
24                 $target .= $filename;
25         }
26         else {
27                 $target .= $input['name'];
28         }
29
30         if (!@move_uploaded_file($input['tmp_name'], $target)) {
31                 throw new Exception("bestand kon niet worden opgeslagen in $target");
32         }
33
34         foreach (@glob('thumb/*/') as $thumbres) {
35                 # attempt to remove old derivations
36                 @unlink($thumbres . '/' . $target);
37         }
38         return $target;
39 }