kino-php/index.php

72 lines
1.8 KiB
PHP

<!DOCTYPE html>
<html lang="ca">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Dusk Kino</title>
<link rel="icon" type="image/png" href="./favicon.apng" sizes="32x32">
<link href="./normal.css" rel="stylesheet" type="text/css" media="all"/>
</head>
<body>
<h1>Dusk Kino</h1>
<?php
$basedir = "./content";
$_GET["q"] = $_GET["q"] ?? "";
$currentdir = $basedir . ($_GET["q"] ? "/" . $_GET["q"] : "");
//Avoid being able to go back in directory structure
if(strstr($currentdir, "..") || !is_dir($currentdir)) {
echo("404");
die();
}
//Check if home and back buttons are needed
if($currentdir != $basedir) {
echo("<div id=\"navigation\">");
echo("<a href=\"/\">Inici</a><br/>");
//Solve ocurrences where url has ?q=./
if (dirname($_GET["q"]) == ".") {
$parentdir = "";
}
else $parentdir = dirname($_GET["q"]);
echo("<a href=\"?q=" . $parentdir . "\">Arrere</a><br/>");
echo("</div>");
}
echo("<hr style=\"border:2px dashed #e87d3e; margin-bottom: 65px\"/>");
$is_there_files = false;
//Show folder links
$dirs = scandir($currentdir);
echo("<h2>Carpetes</h2>");
foreach($dirs as $file) {
if ($file[0] != '.' && is_dir("$currentdir/$file")) {
echo("<a href=\"?q=" . ($_GET["q"] ? $_GET["q"] . "/" : "") . "$file\"><b>/$file/</b></a><br/>\n");
}
if(!is_dir("$currentdir/$file")) $is_there_files = true;
}
if($is_there_files){
echo("<hr/>");
//Show file links
echo("<h2>Fitxers</h2>");
echo("<div id=\"files\">");
foreach($dirs as $file) {
if ($file[0] != '.' && !is_dir("$currentdir/$file")) {
echo("<a href=\"$currentdir/$file\"><b>$file</b></a><br/>\n");
}
}
echo("</div>");
}
printf('<p class="path">/%s</p>', $_GET["q"]);
?>
</body>
</html>