setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $userManager = new \pvv\admin\UserManager($pdo); $as = new SimpleSAML_Auth_Simple('default-sp'); $as->requireAuth(); $attrs = $as->getAttributes(); $uname = $attrs['uid'][0]; if(!$uname){ header('Content-Type: text/plain', true, 403); echo "Du må være logget inn for å se bildegalleriet.\r\n"; exit(); } $unamefile = __DIR__ . '/usernames.txt'; $unamepairs = file($unamefile); $relativePath = "/bilder/pvv-photos/"; $fullPath = getcwd() . $relativePath; function getDirContents($dir, &$results = array()) { $files = scandir($dir); foreach ($files as $key => $value) { $path = realpath($dir . DIRECTORY_SEPARATOR . $value); if (!is_dir($path)) { //$results[] = str_replace($GLOBALS["fullPath"], "", $path); // Works, but breaks if the image path contains the path to the gallery on the server //Remove the full path to the gallery from the image path. Keep username and path to image. $pos = strpos($path, $GLOBALS["fullPath"]); if ($pos !== false) { $cleanPath = substr_replace($path, "", $pos, strlen($GLOBALS["fullPath"])); } $results[] = $cleanPath; } else if ($value != "." && $value != "..") { //recursively scan directories getDirContents($path, $results); } } return $results; } $images = getDirContents($fullPath); $imageTemplate = ' '; ?> Fotoverkstedet
Fotoverkstedet
$value) { $modTime = date("d.m.Y H:i", filemtime($fullPath . $value)); $imguser = explode("/", $value)[0]; $displaypath = substr($value, strpos($value, "/")+1); $realname = "Ukjent"; foreach ($unamepairs as $unamepair) { $unamepair = explode(":", $unamepair); if ($unamepair[0] == $imguser) { $realname = $unamepair[1]; break; } } $vars = [ "%user" => $imguser, "%time" => $modTime, "%name" => $displaypath, "%path" => "/galleri/" . $relativePath .$value, "%realname" => $realname ]; echo strtr($imageTemplate, $vars); } ?>