Upload 4 files
Browse files- index.php +42 -0
- manage_albums.php +115 -0
- show_album.php +24 -0
- styles.css +78 -0
index.php
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="zh-CN">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<title>简易网络相册</title>
|
6 |
+
<link rel="stylesheet" href="styles.css">
|
7 |
+
<style>
|
8 |
+
.albums-grid {
|
9 |
+
display: grid;
|
10 |
+
grid-template-columns: repeat(5, 1fr); /* 创建4列 */
|
11 |
+
gap: 10px; /* 设置网格项之间的间隙 */
|
12 |
+
}
|
13 |
+
.albums-grid li {
|
14 |
+
list-style: none; /* 移除默认列表样式 */
|
15 |
+
}
|
16 |
+
</style>
|
17 |
+
</head>
|
18 |
+
<body>
|
19 |
+
<a href="manage_albums.php">管理相册</a> <!-- 新增的管理相册链接 -->
|
20 |
+
<ul class="albums-grid">
|
21 |
+
<?php
|
22 |
+
$albumDir = 'albums/';
|
23 |
+
$albums = glob($albumDir . '*.txt');
|
24 |
+
foreach ($albums as $index => $album) {
|
25 |
+
$albumName = basename($album, '.txt');
|
26 |
+
$imageUrls = file($album, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
27 |
+
$thumbnailUrl = $imageUrls[0]; // 假设每个.txt文件的第一行是缩略图
|
28 |
+
|
29 |
+
// 缩略图现在被包裹在一个链接中,点击可以打开相册
|
30 |
+
echo "<li><a href='show_album.php?album=$albumName'>";
|
31 |
+
echo "<img src='$thumbnailUrl' alt='Thumbnail' class='album-thumbnail'></a>";
|
32 |
+
echo "<a href='show_album.php?album=$albumName'>$albumName</a></li>";
|
33 |
+
|
34 |
+
// 在每4个相册后添加一个新行
|
35 |
+
if (($index + 1) % 4 == 0) {
|
36 |
+
echo "</ul><ul class='albums-grid'>";
|
37 |
+
}
|
38 |
+
}
|
39 |
+
echo "</ul>";
|
40 |
+
?>
|
41 |
+
</body>
|
42 |
+
</html>
|
manage_albums.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
session_start(); // 开始会话
|
3 |
+
|
4 |
+
$albumDir = 'albums/';
|
5 |
+
$albums = glob($albumDir . '*.txt');
|
6 |
+
$correctPassword = 'addroot'; // 设置固定的口令
|
7 |
+
|
8 |
+
// 检查会话中的口令或表单提交的口令
|
9 |
+
if (isset($_SESSION['password']) && $_SESSION['password'] === $correctPassword) {
|
10 |
+
// 口令正确,显示管理界面
|
11 |
+
|
12 |
+
// 处理备份请求
|
13 |
+
if (isset($_POST['backup'])) {
|
14 |
+
$zip = new ZipArchive();
|
15 |
+
$backupFileName = $albumDir . 'backup_' . date('YmdHis') . '.zip';
|
16 |
+
if ($zip->open($backupFileName, ZipArchive::CREATE) === TRUE) {
|
17 |
+
foreach ($albums as $album) {
|
18 |
+
$zip->addFile($album, basename($album));
|
19 |
+
}
|
20 |
+
$zip->close();
|
21 |
+
|
22 |
+
// 触发下载
|
23 |
+
header('Content-Type: application/zip');
|
24 |
+
header('Content-Disposition: attachment; filename="' . basename($backupFileName) . '"');
|
25 |
+
header('Content-Length: ' . filesize($backupFileName));
|
26 |
+
flush();
|
27 |
+
readfile($backupFileName);
|
28 |
+
// 删除服务器上的备份文件
|
29 |
+
unlink($backupFileName);
|
30 |
+
exit;
|
31 |
+
} else {
|
32 |
+
echo "<p>备份失败。</p>";
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
// 显示备份按钮
|
37 |
+
echo "<form method='post'>";
|
38 |
+
echo "<input type='submit' name='backup' value='备份相册'>";
|
39 |
+
echo "</form>";
|
40 |
+
|
41 |
+
// ... 其他管理界面的代码 ...
|
42 |
+
|
43 |
+
} elseif (isset($_POST['password'])) {
|
44 |
+
if ($_POST['password'] === $correctPassword) {
|
45 |
+
// 口令正确,保存口令到会话
|
46 |
+
$_SESSION['password'] = $_POST['password'];
|
47 |
+
// 重定向到相同页面,避免表单重复提交
|
48 |
+
header('Location: ' . $_SERVER['PHP_SELF']);
|
49 |
+
exit;
|
50 |
+
} else {
|
51 |
+
// 口令错误,显示错误信息
|
52 |
+
echo "<p>口令错误,请重试。</p>";
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
// 如果口令正确,显示管理界面的其他操作
|
57 |
+
if (isset($_SESSION['password']) && $_SESSION['password'] === $correctPassword) {
|
58 |
+
// 处理表单提交的其他操作,如添加和删除图片
|
59 |
+
if (isset($_POST['add'])) {
|
60 |
+
// 批量添加新图片
|
61 |
+
$albumName = $_POST['albumName'];
|
62 |
+
$imageUrls = explode("\n", $_POST['imageUrls']); // 从文本区域获取多个URL
|
63 |
+
foreach ($imageUrls as $imageUrl) {
|
64 |
+
if (!empty($imageUrl)) {
|
65 |
+
file_put_contents("$albumDir$albumName.txt", trim($imageUrl) . "\n", FILE_APPEND);
|
66 |
+
}
|
67 |
+
}
|
68 |
+
} elseif (isset($_POST['delete'])) {
|
69 |
+
// 删除图片
|
70 |
+
$albumName = $_POST['albumName'];
|
71 |
+
$imageUrl = $_POST['imageUrl'];
|
72 |
+
$images = file("$albumDir$albumName.txt", FILE_IGNORE_NEW_LINES);
|
73 |
+
$images = array_filter($images, function ($line) use ($imageUrl) {
|
74 |
+
return trim($line) !== trim($imageUrl);
|
75 |
+
});
|
76 |
+
file_put_contents("$albumDir$albumName.txt", implode("\n", $images) . "\n");
|
77 |
+
} elseif (isset($_POST['create'])) {
|
78 |
+
// 新增相册
|
79 |
+
$newAlbumName = $_POST['newAlbumName'];
|
80 |
+
$newAlbumFile = "$albumDir$newAlbumName.txt";
|
81 |
+
if (!file_exists($newAlbumFile)) {
|
82 |
+
fclose(fopen($newAlbumFile, 'w'));
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
// 显示新增相册表单
|
87 |
+
echo "<a href='index.php'>返回首页</a>"; // 添加返回首页的导航链接
|
88 |
+
echo "<form method='post'>";
|
89 |
+
echo "<input type='text' name='newAlbumName' placeholder='输入新相册名称'>";
|
90 |
+
echo "<input type='submit' name='create' value='创建新相册'>";
|
91 |
+
echo "</form>";
|
92 |
+
|
93 |
+
// 显示现有相册和图片管理界面
|
94 |
+
foreach ($albums as $album) {
|
95 |
+
$albumName = basename($album, '.txt');
|
96 |
+
echo "<div><h3>$albumName</h3>";
|
97 |
+
$imageUrls = file($album, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
98 |
+
foreach ($imageUrls as $imageUrl) {
|
99 |
+
// 显示图片URL、删除按钮和30x30的缩略图
|
100 |
+
echo "<p>$imageUrl <form method='post' style='display: inline;'><input type='hidden' name='albumName' value='$albumName'><input type='hidden' name='imageUrl' value='$imageUrl'><input type='submit' name='delete' value='删除'></form> <img src='$imageUrl' alt='Thumbnail' width='30' height='30'></p>";
|
101 |
+
}
|
102 |
+
// 修改后的添加图片表单,包含一个文本区域用于批量输入URL
|
103 |
+
echo "<form method='post'><input type='hidden' name='albumName' value='$albumName'><textarea name='imageUrls' placeholder='输入图片URL,每行一个' style='width: 500px; height: 100px;'></textarea><input type='submit' name='add' value='批量添加图片'></form>";
|
104 |
+
echo "</div>";
|
105 |
+
}
|
106 |
+
} else {
|
107 |
+
// 显示口令输入表单
|
108 |
+
echo "<form method='post'>";
|
109 |
+
echo "<input type='password' name='password' placeholder='输入口令'>";
|
110 |
+
echo "<input type='submit' value='提交'>";
|
111 |
+
echo "</form>";
|
112 |
+
}
|
113 |
+
?>
|
114 |
+
</body>
|
115 |
+
</html>
|
show_album.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="zh-CN">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<title>相册展示</title>
|
6 |
+
<link rel="stylesheet" href="styles.css">
|
7 |
+
</head>
|
8 |
+
<body>
|
9 |
+
<?php
|
10 |
+
if (isset($_GET['album'])) {
|
11 |
+
$albumName = $_GET['album'];
|
12 |
+
$albumFile = "albums/$albumName.txt";
|
13 |
+
$imageUrls = file($albumFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
14 |
+
|
15 |
+
echo "<div class='waterfall'>";
|
16 |
+
foreach ($imageUrls as $imageUrl) {
|
17 |
+
// 每张图片都被一个链接包裹,点击后可以在新标签页中完整打开图片
|
18 |
+
echo "<div class='item'><a href='$imageUrl' target='_blank'><img src='$imageUrl' alt='Photo'></a></div>";
|
19 |
+
}
|
20 |
+
echo "</div>";
|
21 |
+
}
|
22 |
+
?>
|
23 |
+
</body>
|
24 |
+
</html>
|
styles.css
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* ��վȫ����ʽ */
|
2 |
+
body {
|
3 |
+
font-family: Arial, sans-serif;
|
4 |
+
margin: 0;
|
5 |
+
padding: 0;
|
6 |
+
background-color: #f4f4f4;
|
7 |
+
}
|
8 |
+
|
9 |
+
/* ������ʽ */
|
10 |
+
form {
|
11 |
+
margin-bottom: 20px;
|
12 |
+
}
|
13 |
+
|
14 |
+
input[type="text"],
|
15 |
+
input[type="password"] {
|
16 |
+
padding: 5px;
|
17 |
+
margin-right: 10px;
|
18 |
+
}
|
19 |
+
|
20 |
+
input[type="submit"] {
|
21 |
+
padding: 5px 15px;
|
22 |
+
cursor: pointer;
|
23 |
+
}
|
24 |
+
|
25 |
+
/* ��������ʽ */
|
26 |
+
h2, h3 {
|
27 |
+
color: #333;
|
28 |
+
}
|
29 |
+
|
30 |
+
div {
|
31 |
+
background-color: #fff;
|
32 |
+
padding: 15px;
|
33 |
+
margin-bottom: 20px;
|
34 |
+
border-radius: 5px;
|
35 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
36 |
+
}
|
37 |
+
|
38 |
+
|
39 |
+
/* �������ͼ��ʽ */
|
40 |
+
.album-thumbnail {
|
41 |
+
width: 100px; /* ��������ͼ�Ŀ���Ϊ30���� */
|
42 |
+
height: 100px; /* ��������ͼ�ĸ߶�Ϊ30���� */
|
43 |
+
object-fit: cover; /* ȷ��ͼƬ����ʧ�� */
|
44 |
+
margin-right: 10px;
|
45 |
+
}
|
46 |
+
|
47 |
+
/* �ٲ���������ʽ */
|
48 |
+
.waterfall {
|
49 |
+
column-count: 4; /* �����Ը�����Ҫ�������� */
|
50 |
+
column-gap: 10px; /* ������֮��ļ�� */
|
51 |
+
margin: 0 10px;
|
52 |
+
}
|
53 |
+
|
54 |
+
.waterfall .item {
|
55 |
+
break-inside: avoid; /* ��ֹͼƬ���зָ� */
|
56 |
+
margin-bottom: 10px; /* ͼƬ��ͼƬ֮��ļ�� */
|
57 |
+
}
|
58 |
+
|
59 |
+
.waterfall img {
|
60 |
+
width: 300px; /* ����ͼƬ�Ŀ���Ϊ300���� */
|
61 |
+
height: 300px; /* ����ͼƬ�ĸ߶�Ϊ300���� */
|
62 |
+
object-fit: cover; /* ����ͼƬ�ı���������IJ��ֻᱻ�ü� */
|
63 |
+
border-radius: 5px; /* ��ѡ��ΪͼƬ����Բ�DZ߿� */
|
64 |
+
box-shadow: 0 4px 8px rgba(0,0,0,0.1); /* ��ѡ��ΪͼƬ������Ӱ */
|
65 |
+
}
|
66 |
+
|
67 |
+
/* ��Ӧʽ��ƣ�������Ļ��С�����ٲ������� */
|
68 |
+
@media (max-width: 800px) {
|
69 |
+
.waterfall {
|
70 |
+
column-count: 2;
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
@media (max-width: 400px) {
|
75 |
+
.waterfall {
|
76 |
+
column-count: 1;
|
77 |
+
}
|
78 |
+
}
|