ab86a2f8e71e1abb02e7de640dd932a11f3df7b8
[minimedit.git] / edit / foto / cover / index.php
1 <?php
2 if (!$User or !$User->admin('foto')) {
3         http_response_code(403);
4         print "Beheerrechten verplicht voor instellen van covers\n";
5         exit;
6 }
7
8 $rootdir = 'foto' . $Args;
9 $target = "$rootdir/index.jpg";
10
11 if (is_link($target) or file_exists($target)) {
12         if (!unlink($target)) {
13                 http_response_code(500);
14                 print "Kon bestaande cover niet weghalen voor $Args\n";
15                 exit;
16         }
17 }
18
19 if (isset($_GET['img'])) {
20         $img = str_repeat('../', substr_count($target, '/')); # up to docroot
21         $img .= ltrim($_GET['img'], '/');
22         if (!symlink($img, $target)) {
23                 http_response_code(500);
24                 print "Fout bij instellen van cover voor $Args\n";
25                 exit;
26         }
27 }
28
29 $album = pathinfo($rootdir);
30 header("Location: /{$album['dirname']}#{$album['basename']}");
31 http_response_code(302);
32 exit;