edit: move fotocover page to foto/ subdirectory
[minimedit.git] / edit / foto / cover / index.php
diff --git a/edit/foto/cover/index.php b/edit/foto/cover/index.php
new file mode 100644 (file)
index 0000000..feddc8d
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+ob_clean();
+
+if (empty($User['admin'])) {
+       http_response_code(403);
+       print "Beheerrechten verplicht voor instellen van covers\n";
+       exit;
+}
+
+$rootdir = 'foto' . $Args;
+$target = "$rootdir/index.jpg";
+
+if (is_link($target) or file_exists($target)) {
+       if (!unlink($target)) {
+               http_response_code(500);
+               print "Kon bestaande cover niet weghalen voor $Args\n";
+               exit;
+       }
+}
+
+if (isset($_GET['img'])) {
+       $img = str_repeat('../', substr_count($target, '/')); # up to docroot
+       $img .= ltrim($_GET['img'], '/');
+       if (!symlink($img, $target)) {
+               http_response_code(500);
+               print "Fout bij instellen van cover voor $Args\n";
+               exit;
+       }
+}
+
+$album = pathinfo($rootdir);
+header("Location: /{$album['dirname']}#{$album['basename']}");
+http_response_code(302);