|
<?php |
|
session_start(); |
|
|
|
$albumDir = 'albums/'; |
|
$albums = glob($albumDir . '*.txt'); |
|
$correctPassword = 'addroot'; |
|
|
|
|
|
if (isset($_POST['backup']) && isset($_SESSION['password']) && $_SESSION['password'] === $correctPassword) { |
|
$zip = new ZipArchive(); |
|
$backupFileName = $albumDir . 'backup_' . date('YmdHis') . '.zip'; |
|
if ($zip->open($backupFileName, ZipArchive::CREATE) === TRUE) { |
|
foreach ($albums as $album) { |
|
$zip->addFile($album, basename($album)); |
|
} |
|
$zip->close(); |
|
|
|
|
|
header('Content-Type: application/zip'); |
|
header('Content-Disposition: attachment; filename="' . basename($backupFileName) . '"'); |
|
header('Content-Length: ' . filesize($backupFileName)); |
|
ob_clean(); |
|
flush(); |
|
readfile($backupFileName); |
|
|
|
unlink($backupFileName); |
|
exit; |
|
} else { |
|
echo "<p>备份失败。</p>"; |
|
} |
|
} |
|
|
|
|
|
if (isset($_SESSION['password']) && $_SESSION['password'] === $correctPassword) { |
|
|
|
|
|
|
|
echo "<div style='display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px;'>"; |
|
echo "<a href='index.php' style='text-decoration: none;'>"; |
|
echo "<button type='button'>返回首页</button>"; |
|
echo "</a>"; |
|
echo "<form method='post'>"; |
|
echo "<input type='submit' name='backup' value='备份相册'>"; |
|
echo "</form>"; |
|
echo "</div>"; |
|
|
|
|
|
if (isset($_POST['create']) && !empty($_POST['newAlbumName'])) { |
|
$newAlbumName = trim($_POST['newAlbumName']); |
|
$newAlbumFile = $albumDir . $newAlbumName . '.txt'; |
|
if (!file_exists($newAlbumFile)) { |
|
file_put_contents($newAlbumFile, ''); |
|
echo "<p>新相册 '{$newAlbumName}' 创建成功。</p>"; |
|
} else { |
|
echo "<p>相册 '{$newAlbumName}' 已存在。</p>"; |
|
} |
|
} |
|
|
|
|
|
if (isset($_GET['album'])) { |
|
$albumName = basename($_GET['album'], '.txt'); |
|
$albumFile = $albumDir . $albumName . '.txt'; |
|
|
|
|
|
echo "<h2>管理相册: $albumName</h2>"; |
|
echo "<a href='?'>返回相册列表</a><br>"; |
|
|
|
|
|
if (isset($_POST['add'])) { |
|
$imageUrls = explode("\n", $_POST['imageUrls']); |
|
foreach ($imageUrls as $imageUrl) { |
|
if (!empty($imageUrl)) { |
|
file_put_contents($albumFile, trim($imageUrl) . "\n", FILE_APPEND); |
|
} |
|
} |
|
} |
|
|
|
|
|
if (isset($_POST['delete'])) { |
|
$imageUrl = $_POST['imageUrl']; |
|
$images = file($albumFile, FILE_IGNORE_NEW_LINES); |
|
$images = array_filter($images, function ($line) use ($imageUrl) { |
|
return trim($line) !== trim($imageUrl); |
|
}); |
|
file_put_contents($albumFile, implode("\n", $images) . "\n"); |
|
} |
|
|
|
|
|
$images = file($albumFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
echo "<div style='display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;'>"; |
|
foreach ($images as $imageUrl) { |
|
echo "<div style='text-align: center;'>"; |
|
echo "<a href='$imageUrl'><img src='$imageUrl' alt='Thumbnail' width='100' height='100'></a>"; |
|
echo "<form method='post' style='display: inline;' onsubmit='return confirmDelete();'>"; |
|
echo "<input type='hidden' name='imageUrl' value='$imageUrl'>"; |
|
echo "<input type='submit' name='delete' value='删除'>"; |
|
echo "</form>"; |
|
echo "</div>"; |
|
} |
|
echo "</div>"; |
|
|
|
|
|
echo "<form method='post' style='margin-top: 20px;'>"; |
|
echo "<textarea name='imageUrls' placeholder='输入图片URL,每行一个' style='width: 500px; height: 100px;'></textarea>"; |
|
echo "<input type='submit' name='add' value='批量添加图片'>"; |
|
echo "</form>"; |
|
|
|
} else { |
|
|
|
echo "<h2>相册列表</h2>"; |
|
echo "<div style='display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;'>"; |
|
foreach ($albums as $album) { |
|
$albumName = basename($album, '.txt'); |
|
echo "<a href='?album=$albumName' style='text-align: center;'>$albumName</a>"; |
|
} |
|
echo "</div>"; |
|
|
|
|
|
echo "<form method='post' style='margin-top: 20px;'>"; |
|
echo "<input type='text' name='newAlbumName' placeholder='输入新相册名称'>"; |
|
echo "<input type='submit' name='create' value='创建新相册'>"; |
|
echo "</form>"; |
|
} |
|
|
|
} elseif (isset($_POST['password']) && $_POST['password'] === $correctPassword) { |
|
|
|
$_SESSION['password'] = $_POST['password']; |
|
|
|
header('Location: ' . $_SERVER['PHP_SELF']); |
|
exit; |
|
} else { |
|
|
|
echo "<form method='post'>"; |
|
echo "<input type='password' name='password' placeholder='输入口令'>"; |
|
echo "<input type='submit' value='提交'>"; |
|
echo "</form>"; |
|
} |
|
?> |
|
<script> |
|
|
|
function confirmDelete() { |
|
return confirm('确定要删除这张图片吗?'); |
|
} |
|
</script> |
|
<!-- HTML 内容 --> |
|
</body> |
|
</html> |
|
|