88 lines
2.7 KiB
PHP
88 lines
2.7 KiB
PHP
<?php
|
|
|
|
session_start();
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
if (!file_exists(UPLOAD_DIR)) mkdir(UPLOAD_DIR);
|
|
if (!file_exists(CHUNK_DIR)) mkdir(CHUNK_DIR);
|
|
|
|
if (!isset($_SESSION['logged_in']) || ($_GET['action'] ?? '') === 'logout') {
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['password'] ?? '') === PASSWORD) {
|
|
$_SESSION['logged_in'] = true;
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
echo '<form method="post">
|
|
<h3>Login</h3>
|
|
<input type="password" name="password" placeholder="Password">
|
|
<button type="submit">Login</button>
|
|
</form>';
|
|
exit;
|
|
}
|
|
|
|
// Удаление
|
|
if (isset($_GET['delete'])) {
|
|
$f = basename($_GET['delete']);
|
|
@unlink(UPLOAD_DIR . $f);
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
$files = array_diff(scandir(UPLOAD_DIR), ['.', '..']);
|
|
?><!DOCTYPE html>
|
|
<html>
|
|
<head><meta charset="utf-8"><title>Файловое хранилище</title></head>
|
|
<body>
|
|
<h3>Файловое хранилище</h3>
|
|
<p><a href="?action=logout">Выйти</a></p>
|
|
<input type="file" id="fileInput">
|
|
<div id="progress"></div>
|
|
<ul>
|
|
<?php foreach ($files as $file): $url = 'upload/' . rawurlencode($file); ?>
|
|
<li>
|
|
<?= htmlspecialchars($file) ?>
|
|
[<a href="<?= $url ?>" target="_blank">Скачать</a>]
|
|
[<a href="?delete=<?= urlencode($file) ?>" onclick="return confirm('Удалить?')">Удалить</a>]
|
|
<button onclick="copyLink('<?= $url ?>')">Копировать ссылку</button>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
|
|
<script>
|
|
function copyLink(link) {
|
|
navigator.clipboard.writeText(location.origin + '/' + link).then(() => alert("Скопировано"));
|
|
}
|
|
|
|
const input = document.getElementById('fileInput');
|
|
input.addEventListener('change', async () => {
|
|
const file = input.files[0];
|
|
if (!file) return;
|
|
const chunkSize = 1024 * 1024; // 1MB
|
|
const totalChunks = Math.ceil(file.size / chunkSize);
|
|
|
|
for (let i = 0; i < totalChunks; i++) {
|
|
const chunk = file.slice(i * chunkSize, (i + 1) * chunkSize);
|
|
const formData = new FormData();
|
|
formData.append('chunk', chunk);
|
|
formData.append('filename', file.name);
|
|
formData.append('index', i);
|
|
formData.append('total', totalChunks);
|
|
|
|
await fetch('upload_chunk.php', { method: 'POST', body: formData });
|
|
document.getElementById('progress').innerText = `Загружено: ${i+1}/${totalChunks}`;
|
|
}
|
|
|
|
await fetch('merge_chunks.php', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ filename: file.name, total: totalChunks })
|
|
});
|
|
|
|
alert('Готово!');
|
|
location.reload();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|