Stranka/index.php

82 lines
3.0 KiB
PHP
Raw Normal View History

2024-05-14 16:30:25 +02:00
<?php
2024-05-29 12:19:55 +02:00
$target_dir = "uploads/";
2024-05-14 16:30:25 +02:00
2024-05-29 12:30:50 +02:00
if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST["submit"]) && sha1($_POST["heslo"]) === "5cfce6e9a82aa4cd75657d76ce21111624f20f3f") {
2024-05-29 12:07:26 +02:00
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
2024-05-14 16:30:25 +02:00
2024-05-29 12:07:26 +02:00
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
2024-05-14 16:30:25 +02:00
2024-05-29 12:07:26 +02:00
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
2024-05-14 16:30:25 +02:00
2024-05-29 12:07:26 +02:00
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
2024-05-29 12:19:55 +02:00
echo "The file " . htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " has been uploaded.";
header("Location: https://slovania.adlerka.top/index.php?dano");
2024-05-29 12:07:26 +02:00
} else {
echo "Sorry, there was an error uploading your file.";
}
}
} else {
2024-05-14 16:30:25 +02:00
2024-05-29 12:07:26 +02:00
$skeleton = file_get_contents('templates/skeleton.html');
2024-05-14 16:30:25 +02:00
2024-06-04 14:50:41 +02:00
$menu_obsah = file_get_contents('templates/header.html');
2024-05-29 19:33:22 +02:00
$out = str_replace('__TEMPLATE_HEADER__', $menu_obsah, $skeleton);
2024-05-29 12:07:26 +02:00
$footer_obsah = file_get_contents('templates/footer.html');
$out = str_replace('__TEMPLATE_FOOTER__', $footer_obsah, $out);
2024-05-14 16:30:25 +02:00
2024-05-29 12:07:26 +02:00
$nazov_stranky = basename($_SERVER['QUERY_STRING']);
if (empty($nazov_stranky)) {
$nazov_stranky = 'index';
}
if (!empty($_GET["listfiles"])) {
$files = scandir($target_dir);
$out = "<tr><th>Názov súboru</th><th>Download</th></tr>";
foreach ($files as $file) {
2024-05-29 12:26:03 +02:00
if (!str_starts_with($file, '.')) {
$filename = $file;
$displayname = explode('.', $filename)[0];
$filepath = "/uploads/$file";
$out .= "<tr><td>$displayname</td><td><a href='$filepath' download>$filename</a></td></tr>";
}
2024-05-29 12:07:26 +02:00
}
} else {
$cesta_k_stranke = "stranky/$nazov_stranky.html";
if (!file_exists($cesta_k_stranke)) {
2024-06-05 17:13:18 +02:00
$cesta_k_stranke = "templates/404.html";
2024-05-29 12:07:26 +02:00
}
$stranka_obsah = file_get_contents($cesta_k_stranke);
$out = str_replace('__TEMPLATE_STRANKA__', $stranka_obsah, $out);
$cesta_k_skriptu = "scripty/$nazov_stranky.js";
2024-05-29 12:19:55 +02:00
$script_obsah = "<script defer src=\"$cesta_k_skriptu\"></script>";
2024-05-29 12:07:26 +02:00
if (!file_exists($cesta_k_skriptu)) {
$script_obsah = '';
}
$out = str_replace('__TEMPLATE_SCRIPT__', $script_obsah, $out);
$cesta_k_stylu = "styles/$nazov_stranky.css";
$style_obsah = "<link rel=\"stylesheet\" href=\"$cesta_k_stylu\">";
if (!file_exists($cesta_k_stylu)) {
$style_obsah = '';
}
$out = str_replace('__TEMPLATE_STYLE__', $style_obsah, $out);
}
echo $out;
}