kino-php/index.php

91 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2021-08-28 22:43:04 +00:00
<!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();
}
2021-08-29 19:09:13 +00:00
2021-08-28 22:43:04 +00:00
echo("<hr style=\"border:2px dashed #e87d3e; margin-bottom: 65px\"/>");
2021-08-29 19:09:13 +00:00
$directories = [];
$files = [];
2021-08-28 22:43:04 +00:00
$dirs = scandir($currentdir);
2021-08-29 19:09:13 +00:00
2021-08-28 22:43:04 +00:00
foreach($dirs as $file) {
2021-08-29 19:09:13 +00:00
if ($file[0] != '.') {
if (is_dir("$currentdir/$file")) {
array_push($directories, $file);
}
else {
array_push($files, $file);
}
2021-08-28 22:43:04 +00:00
}
}
2021-08-29 19:09:13 +00:00
//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/>");
2021-08-28 22:43:04 +00:00
//Show file links
echo("<h2>Fitxers</h2>");
echo("<div id=\"files\">");
2021-08-29 19:09:13 +00:00
foreach($files as $file) {
printf('<a href="%s/%s"><b>%s</b></a><br/>' ,
$currentdir, $file, $file);
printf("\n");
2021-08-28 22:43:04 +00:00
}
echo("</div>");
}
2021-08-29 19:09:13 +00:00
2021-08-28 22:43:04 +00:00
printf('<p class="path">/%s</p>', $_GET["q"]);
2021-09-21 20:50:09 +00:00
//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>");
}
2021-08-28 22:43:04 +00:00
?>
</body>
</html>