nieuws/feed: atom content type and link attributes
[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_NO_FILE:
8                 return; # current
9         default:
10                 throw new Exception('bestand niet goed ontvangen: '.$input['error']);
11         }
12
13         if (isset($target)) {
14                 if (!file_exists($target) and !@mkdir($target, 0777, TRUE)) {
15                         throw new Exception("bestand kon niet geplaatst worden in $target");
16                 }
17                 $target .= '/';
18         }
19         if (isset($filename)) {
20                 $target .= $filename;
21         }
22         else {
23                 $target .= $input['name'];
24         }
25
26         if (!@move_uploaded_file($input['tmp_name'], $target)) {
27                 throw new Exception('bestand kon niet worden opgeslagen');
28         }
29
30         foreach (@glob('thumb/*/') as $thumbres) {
31                 # attempt to remove old derivations
32                 @unlink($thumbres . '/' . $target);
33         }
34         return $target;
35 }