kino-php/index.php

91 lines
2.0 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();
}
echo("<hr style=\"border:2px dashed #e87d3e; margin-bottom: 65px\"/>");
$directories = [];
$files = [];
$dirs = scandir($currentdir);
foreach($dirs as $file) {
if ($file[0] != '.') {
if (is_dir("$currentdir/$file")) {
array_push($directories, $file);
}
else {
array_push($files, $file);
}
}
}
//Show folder links
if(count($directories) > 0) {
echo("<h2>Carpetes</h2>");
foreach($directories as $file) {
printf('<a href="?q=%s%s"><b>/%s/</b></a><br/>' . "\n" ,
$_GET["q"] ? $_GET["q"] . "/" : "", $file, $file);
}
}
//Show Files
if(count($files) > 0) {
if (count($directories) > 0) echo("<hr/>");
//Show file links
echo("<h2>Fitxers</h2>");
echo("<div id=\"files\">");
foreach($files as $file) {
printf('<a href="%s/%s"><b>%s</b></a><br/>' ,
$currentdir, $file, $file);
printf("\n");
}
echo("</div>");
}
printf('<p class="path">/%s</p>', $_GET["q"]);
//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>");
}
?>
</body>
</html>