some lesson

This commit is contained in:
Aleksandr Shelkovin 2025-01-22 22:23:09 +03:00
parent 425591aba7
commit a4a6e36b3e
21 changed files with 172 additions and 85 deletions

View File

@ -570,10 +570,6 @@ video {
position: fixed;
}
.relative {
position: relative;
}
.left-0 {
left: 0px;
}
@ -699,10 +695,6 @@ video {
height: 100vh;
}
.min-h-screen {
min-height: 100vh;
}
.w-10 {
width: 2.5rem;
}
@ -814,10 +806,6 @@ video {
align-self: center;
}
.overflow-hidden {
overflow: hidden;
}
.overflow-y-auto {
overflow-y: auto;
}
@ -883,6 +871,11 @@ video {
background-color: rgb(219 234 254 / var(--tw-bg-opacity, 1));
}
.bg-blue-500 {
--tw-bg-opacity: 1;
background-color: rgb(59 130 246 / var(--tw-bg-opacity, 1));
}
.bg-blue-700 {
--tw-bg-opacity: 1;
background-color: rgb(29 78 216 / var(--tw-bg-opacity, 1));
@ -1107,6 +1100,11 @@ video {
transition-duration: 75ms;
}
.hover\:bg-blue-700:hover {
--tw-bg-opacity: 1;
background-color: rgb(29 78 216 / var(--tw-bg-opacity, 1));
}
.hover\:bg-gray-100:hover {
--tw-bg-opacity: 1;
background-color: rgb(243 244 246 / var(--tw-bg-opacity, 1));

View File

@ -1,12 +1,12 @@
<?php
require_once __DIR__ . "/../model/AboutModule.php";
require_once __DIR__ . "/../model/MusicModule.php";
require_once __DIR__ . "/../view/View.php";
class AboutController
{
public function actionIndex()
{
$result = AboutModel::getData();
$result = MusicModel::getData();
// var_dump($result);
echo (View::render([
'box' => $result,

View File

@ -1,9 +1,7 @@
<?php
session_start();
require_once __DIR__ . "/../view/View.php";
class AdminController
{
@ -14,7 +12,7 @@ class AdminController
isset($_SESSION['IS_AUTH'])
and $_SESSION['IS_AUTH'] == true
) {
echo (View::render([], 'admin.php'));
echo (View::render(['content' => ''], 'layout_admin.php'));
} else {
header("Location:http://localhost:8000/login");
};

View File

@ -6,7 +6,7 @@ class AuthController
{
const PASSWD = 123;
const LOGIN = 'none@none.ru';
const DOMAIN = 'http://localhost:8000/admin';
const DOMAIN = 'http://localhost:8000/';
public $login = null;
public $password = null;
@ -26,10 +26,10 @@ class AuthController
// setcookie("password", $this->password, time() + 3600); // Истекает через 1 час
// header("Set-Cookie: login=$login; Secure; Path=/; SameSite=None; Partitioned;");
// header("Set-Cookie: passwd=$password; Secure; Path=/; SameSite=None; Partitioned;");
header("Location:". self::DOMAIN);
header("Location:". self::DOMAIN."admin");
} else {
// редирект на форму логина с предупреждением
header("Location:http://localhost:8000/login");
header("Location:". self::DOMAIN."login");
}
@ -40,6 +40,9 @@ class AuthController
public function actionLogout()
{
echo ('print Logout');
// echo ('print Logout');
session_unset();
session_destroy();
header("Location:". self::DOMAIN);
}
}

View File

@ -1,12 +1,13 @@
<?php
require_once __DIR__ . "/../model/AboutModule.php";
require_once __DIR__ . "/../model/MusicModel.php";
require_once __DIR__ . "/../view/View.php";
class MainController
{
public function actionIndex() {
echo(View::render([], 'index_tpl.php'));
$result = MusicModel::getData();
echo(View::render(['box' => $result], 'index_tpl.php'));
}

View File

@ -0,0 +1,35 @@
<?php
session_start();
require_once __DIR__ . "/../view/View.php";
class UploadController
{
public function actionIndex()
{
// todo: Вынести проверку авторизации в отдельный модуль
if (
isset($_SESSION['IS_AUTH'])
and $_SESSION['IS_AUTH'] == true
) {
$portial = (View::render([], 'upload_tpl.php'));
echo (View::render(['content' => $portial], 'layout_admin.php'));
} else {
header("Location:http://localhost:8000/login");
};
}
public function actionAddfile()
{
$uploaddir = 'C:\\Lerning\\itmo-php-course\\engine\\uploads\\';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "Файл не содержит ошибок и успешно загрузился на сервер.\n";
} else {
echo "Возможная атака на сервер через загрузку файла!\n";
}
}
}

View File

@ -1,16 +1,16 @@
<?php
class AboutModel
class MusicModel
{
static function getData()
{
$box = [];
if ($handle = opendir('./upload')) {
if ($handle = opendir('./uploads')) {
while (false !== ($entry = readdir($handle))) {
$ext = pathinfo($entry, PATHINFO_EXTENSION);
if ($ext == 'mp3') {
array_push($box, "./upload/$entry");
array_push($box, "./uploads/$entry");
}
}
closedir($handle);

View File

@ -1,13 +0,0 @@
Тип кодирования данных, enctype, требуется указывать только так, как показывает пример
<form enctype="multipart/form-data" action="file_upload.php" method="POST">
Поле MAX_FILE_SIZE требуется указывать перед полем загрузки файла
<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
Название элемента input определяет название элемента в суперглобальном массиве $_FILES
Отправить файл: <input name="userfile" type="file" />
<input type="submit" value="Отправить файл" />
</form>
<label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white" for="file_input">Upload file</label>
<input class="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400" aria-describedby="file_input_help" id="file_input" type="file" value="Отправить файл">
<p class="mt-1 text-sm text-gray-500 dark:text-gray-300" id="file_input_help">SVG, PNG, JPG or GIF (MAX. 800x400px).</p>

View File

@ -29,11 +29,56 @@
<li>
<a href="./login" class="block py-2 px-3 text-white bg-blue-700 rounded md:bg-transparent md:text-blue-700 md:p-0 dark:text-white md:dark:text-blue-500" aria-current="page">Login</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="flex border-b">
<button id="tab1" class="px-4 py-2 border-b-2 border-blue-500 text-blue-500 font-medium active" onclick="showTab('tab1')">Classic</button>
<button id="tab2" class="px-4 py-2 border-b-2 border-transparent text-gray-500 font-medium hover:text-gray-700 hover:border-gray-300" onclick="showTab('tab2')">Jazz</button>
<button id="tab3" class="px-4 py-2 border-b-2 border-transparent text-gray-500 font-medium hover:text-gray-700 hover:border-gray-300" onclick="showTab('tab3')">Rock</button>
</div>
<div id="content1" class="p-4">
<?php foreach ($box as $item): ?>
<audio controls>
<source src="<?php echo $item; ?>" type="audio/mpeg">
</audio>
<?php endforeach; ?>
<div id="content2" class="p-4 hidden">
Содержимое вкладки 2
</div>
<div id="content3" class="p-4 hidden">
Содержимое вкладки 3
</div>
<script>
function showTab(tabId) {
const tabs = document.querySelectorAll('.flex button');
const contents = document.querySelectorAll('.p-4');
tabs.forEach(tab => {
tab.classList.remove('active');
tab.classList.remove('border-blue-500');
tab.classList.remove('text-blue-500');
tab.classList.add('border-transparent');
tab.classList.add('text-gray-500');
});
contents.forEach(content => {
content.classList.add('hidden');
});
document.getElementById(tabId).classList.add('active');
document.getElementById(tabId).classList.add('border-blue-500');
document.getElementById(tabId).classList.add('text-blue-500');
document.getElementById(tabId).classList.remove('border-transparent');
document.getElementById(tabId).classList.remove('text-gray-500');
document.getElementById(`content${tabId.slice(-1)}`).classList.remove('hidden');
}
</script>
</body>

View File

@ -4,7 +4,8 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.tailwindcss.com"></script>
<!-- <script src="https://cdn.tailwindcss.com"></script> -->
<link rel="stylesheet" href="./../../app/assets/css/styles.css">
<title>Resposive Layout</title>
</head>
@ -56,31 +57,22 @@
</a>
</li>
<li>
<a href="#" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
<a href="./upload" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
<svg class="flex-shrink-0 w-5 h-5 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 18 20">
<path d="M17 5.923A1 1 0 0 0 16 5h-3V4a4 4 0 1 0-8 0v1H2a1 1 0 0 0-1 .923L.086 17.846A2 2 0 0 0 2.08 20h13.84a2 2 0 0 0 1.994-2.153L17 5.923ZM7 9a1 1 0 0 1-2 0V7h2v2Zm0-5a2 2 0 1 1 4 0v1H7V4Zm6 5a1 1 0 1 1-2 0V7h2v2Z" />
</svg>
<span class="flex-1 ms-3 whitespace-nowrap">Products</span>
<span class="flex-1 ms-3 whitespace-nowrap">Загрузка</span>
</a>
</li>
<li>
<a href="#" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
<a href="./logout" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
<svg class="flex-shrink-0 w-5 h-5 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 16">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 8h11m0 0L8 4m4 4-4 4m4-11h3a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-3" />
</svg>
<span class="flex-1 ms-3 whitespace-nowrap">Sign In</span>
</a>
</li>
<li>
<a href="#" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
<svg class="flex-shrink-0 w-5 h-5 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M5 5V.13a2.96 2.96 0 0 0-1.293.749L.879 3.707A2.96 2.96 0 0 0 .13 5H5Z" />
<path d="M6.737 11.061a2.961 2.961 0 0 1 .81-1.515l6.117-6.116A4.839 4.839 0 0 1 16 2.141V2a1.97 1.97 0 0 0-1.933-2H7v5a2 2 0 0 1-2 2H0v11a1.969 1.969 0 0 0 1.933 2h12.134A1.97 1.97 0 0 0 16 18v-3.093l-1.546 1.546c-.413.413-.94.695-1.513.81l-3.4.679a2.947 2.947 0 0 1-1.85-.227 2.96 2.96 0 0 1-1.635-3.257l.681-3.397Z" />
<path d="M8.961 16a.93.93 0 0 0 .189-.019l3.4-.679a.961.961 0 0 0 .49-.263l6.118-6.117a2.884 2.884 0 0 0-4.079-4.078l-6.117 6.117a.96.96 0 0 0-.263.491l-.679 3.4A.961.961 0 0 0 8.961 16Zm7.477-9.8a.958.958 0 0 1 .68-.281.961.961 0 0 1 .682 1.644l-.315.315-1.36-1.36.313-.318Zm-5.911 5.911 4.236-4.236 1.359 1.359-4.236 4.237-1.7.339.341-1.699Z" />
</svg>
<span class="flex-1 ms-3 whitespace-nowrap">Sign Up</span>
<span class="flex-1 ms-3 whitespace-nowrap">Log Out</span>
</a>
</li>
</ul>
</div>
</aside>
@ -112,9 +104,12 @@
</div>
<div class="flex items-center justify-center h-48 mb-4 rounded bg-gray-50 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16" />
</svg>
<?php if ($content): ?>
<?php echo $content ?>
<?php else: ?>
<?php echo "Нужен контент" ?>
<?php endif; ?>
</p>
</div>
<div class="grid grid-cols-2 gap-4 mb-4">

View File

@ -28,8 +28,8 @@
<form class="mt-6" action="auth" method="post">
<div>
<label for="email" class="block text-sm text-gray-800">Email</label>
<input type="email"
class="block w-full px-4 py-2 mt-2 text-purple-700 bg-white border rounded-md focus:border-purple-400 focus:ring-purple-300 focus:outline-none focus:ring focus:ring-opacity-40" name="login">
<input type="email"
class="block w-full px-4 py-2 mt-2 text-purple-700 bg-white border rounded-md focus:border-purple-400 focus:ring-purple-300 focus:outline-none focus:ring focus:ring-opacity-40" name="login" value="none@none.ru">
</div>
<div class="mt-4">
<div>

View File

@ -1,39 +1,50 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $pageTitle; ?></title>
<style>
body { font-family: sans-serif; }
.audio-player { margin-bottom: 10px; }
.logout, .login { margin-bottom: 10px; }
body {
font-family: sans-serif;
}
.audio-player {
margin-bottom: 10px;
}
.logout,
.login {
margin-bottom: 10px;
}
</style>
</head>
<body>
<?php if ($auth): ?>
<div class="logout"><a href="logout.php">Выход</a></div>
<?php else: ?>
<div class="login"><a href="login.php">Вход</a></div>
<?php endif; ?>
<?php
$audioFiles = $box; // Переименовали переменную для ясности
foreach ($audioFiles as $file):
if (file_exists($file)) : ?>
<div class="audio-player">
<audio controls="controls">
<source src="<?php echo htmlspecialchars($file); ?>" type="audio/mpeg">
Ваш браузер не поддерживает HTML5 audio.
</audio>
</div>
<?php if ($auth): ?>
<div class="logout"><a href="logout.php">Выход</a></div>
<?php else: ?>
<p>Файл "<?php echo htmlspecialchars($file); ?>" не найден.</p>
<div class="login"><a href="login.php">Вход</a></div>
<?php endif; ?>
<?php
$audioFiles = $box; // Переименовали переменную для ясности
foreach ($audioFiles as $file):
if (file_exists($file)) : ?>
<div class="audio-player">
<audio controls="controls">
<source src="<?php echo htmlspecialchars($file); ?>" type="audio/mpeg">
Ваш браузер не поддерживает HTML5 audio.
</audio>
</div>
<?php else: ?>
<p>Файл "<?php echo htmlspecialchars($file); ?>" не найден.</p>
<?php endif;
endforeach;
?>
endforeach;
?>
</body>
</html>

View File

@ -0,0 +1,11 @@
<form enctype="multipart/form-data" action="file_upload" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000000" />
Отправить файл: <input name="userfile" type="file" />
<input class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" type="submit" value="Отправить файл" />
</form>
<!-- <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white" for="file_input">Upload file</label>
<input class="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400" aria-describedby="file_input_help" id="file_input" type="file" value="Отправить файл">
<p class="mt-1 text-sm text-gray-500 dark:text-gray-300" id="file_input_help">SVG, PNG, JPG or GIF (MAX. 800x400px).</p> -->

View File

@ -4,9 +4,12 @@ return array(
'news' => 'news/index', // actionIndex в NewsController
'products' => 'product/list', // actionList в ProductController
'about' => 'about/index',
'admin' => 'admin/index',
'login' => 'login/index',
'admin' => 'admin/index',
'auth' => 'auth/login',
'logout' => 'auth/logout',
'upload' => 'upload/index',
'file_upload' => 'upload/addfile',
);
// - где 'news' - строка запроса
// 'news/index' - имя контроллера и экшена для обработки этого запроса (путь обработчика)

Binary file not shown.