-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
787 lines (687 loc) · 29.6 KB
/
index.php
File metadata and controls
787 lines (687 loc) · 29.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
<?php
// 配置管理员密码
$adminPassword = "admin123";
// 会话开始
session_start();
// 检查是否为管理员登录
$isAdmin = isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
// 登录处理
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password'])) {
if ($_POST['password'] === $adminPassword) {
$_SESSION['isAdmin'] = true;
header("Location: " . $_SERVER['PHP_SELF']);
exit;
} else {
$errorMessage = "密码错误,请重试。";
}
}
// 登出处理
if (isset($_GET['logout'])) {
session_destroy();
header("Location: " . $_SERVER['PHP_SELF']);
exit;
}
// 获取当前目录
$currentDir = isset($_GET['dir']) ? $_GET['dir'] : '';
$currentDirPath = __DIR__ . '/uploads/' . $currentDir;
// 确保目录存在
if (!is_dir($currentDirPath)) {
mkdir($currentDirPath, 0777, true);
}
// 文件操作处理
if ($isAdmin) {
// 删除文件/目录
if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['path'])) {
$itemPath = __DIR__ . '/uploads/' . urldecode($_GET['path']);
if (is_file($itemPath)) {
unlink($itemPath);
$message = "文件已删除";
} elseif (is_dir($itemPath)) {
// 递归删除目录
$dirIterator = new RecursiveDirectoryIterator($itemPath, RecursiveDirectoryIterator::SKIP_DOTS);
$recursiveIterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($recursiveIterator as $file) {
if ($file->isDir()) {
rmdir($file->getPathname());
} else {
unlink($file->getPathname());
}
}
rmdir($itemPath);
$message = "目录已删除";
}
header("Location: " . $_SERVER['PHP_SELF'] . "?dir=" . urlencode($currentDir));
exit;
}
// 重命名文件/目录
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST['action'] === 'rename') {
$oldPath = __DIR__ . '/uploads/' . urldecode($_POST['oldPath']);
$newPath = __DIR__ . '/uploads/' . urldecode($_POST['newPath']);
if (file_exists($oldPath)) {
rename($oldPath, $newPath);
$message = "已重命名";
}
header("Location: " . $_SERVER['PHP_SELF'] . "?dir=" . urlencode($currentDir));
exit;
}
// 移动文件/目录
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST['action'] === 'move') {
$sourcePath = __DIR__ . '/uploads/' . urldecode($_POST['sourcePath']);
$targetPath = __DIR__ . '/uploads/' . urldecode($_POST['targetPath']);
if (file_exists($sourcePath)) {
// 确保目标目录存在
$targetDir = dirname($targetPath);
if (!is_dir($targetDir)) {
mkdir($targetDir, 0777, true);
}
rename($sourcePath, $targetPath);
$message = "已移动";
}
header("Location: " . $_SERVER['PHP_SELF'] . "?dir=" . urlencode($currentDir));
exit;
}
}
// 新建目录处理
if ($isAdmin && $_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['newDir'])) {
$newDir = $_POST['newDir'];
$newDirPath = $currentDirPath . '/' . $newDir;
if (!is_dir($newDirPath)) {
mkdir($newDirPath, 0777, true);
}
header("Location: " . $_SERVER['PHP_SELF'] . "?dir=" . urlencode($currentDir));
exit;
}
// 文件上传处理
if ($isAdmin && $_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES['files'])) {
foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name) {
$fileName = $_FILES['files']['name'][$key];
$filePath = $currentDirPath . '/' . $fileName;
// 检查文件是否已存在
if (file_exists($filePath)) {
$fileName = time() . '_' . $fileName; // 添加时间戳避免重名
$filePath = $currentDirPath . '/' . $fileName;
}
if (move_uploaded_file($tmp_name, $filePath)) {
$uploadMessage = "文件上传成功";
} else {
$uploadMessage = "文件上传失败";
}
}
}
// 获取当前目录下的文件和子目录
$items = array();
if (is_dir($currentDirPath)) {
$dirIterator = new DirectoryIterator($currentDirPath);
foreach ($dirIterator as $item) {
if ($item->isDot()) continue;
$itemInfo = array(
'name' => $item->getFilename(),
'type' => $item->isDir() ? 'dir' : 'file',
'mtime' => $item->getMTime(),
'path' => $currentDir . ($currentDir ? '/' : '') . $item->getFilename()
);
if ($item->isFile()) {
$itemInfo['size'] = $item->getSize();
$itemInfo['extension'] = $item->getExtension();
}
$items[] = $itemInfo;
}
}
// 排序:目录在前,文件在后,按名称排序
usort($items, function($a, $b) {
if ($a['type'] === $b['type']) {
return strcasecmp($a['name'], $b['name']);
}
return ($a['type'] === 'dir') ? -1 : 1;
});
// 获取所有目录(用于移动操作)
function getAllDirectories($baseDir) {
$dirs = array();
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($baseDir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $fileInfo) {
if ($fileInfo->isDir()) {
$relativePath = str_replace($baseDir, '', $fileInfo->getPathname());
$dirs[] = ltrim($relativePath, '/');
}
}
return $dirs;
}
$allDirs = getAllDirectories(__DIR__ . '/uploads/');
// 生成面包屑导航
$breadcrumbs = array();
$pathParts = explode('/', $currentDir);
$currentPath = '';
foreach ($pathParts as $part) {
if ($part === '') continue;
$currentPath .= ($currentPath ? '/' : '') . $part;
$breadcrumbs[] = array(
'name' => $part,
'path' => $currentPath
);
}
// 提取所有音频文件
$audioFiles = array();
foreach ($items as $item) {
if ($item['type'] === 'file' && in_array(strtolower($item['extension']), array('mp3', 'wav', 'ogg'))) {
$audioFiles[] = $item;
}
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文件管理系统</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
.container { max-width: 1200px; margin: 0 auto; }
.admin-panel { background: #f9f9f9; padding: 15px; margin-bottom: 20px; border-radius: 5px; }
.breadcrumbs { margin-bottom: 15px; }
.breadcrumbs a { text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }
.file-list { width: 100%; border-collapse: collapse; }
.file-list th, .file-list td { padding: 8px; border: 1px solid #ddd; text-align: left; }
.file-list th { background-color: #f2f2f2; }
.preview img { max-width: 100px; max-height: 100px; cursor: pointer; }
.preview audio, .preview video { max-width: 200px; }
.success { color: green; }
.error { color: red; }
.modal {
display: none;
position: fixed;
z-index: 1;
padding-top: 0;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.8);
}
.modal-content {
background-color: transparent;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
position: relative;
}
.close {
color: white;
position: absolute;
top: 20px;
right: 30px;
font-size: 40px;
font-weight: bold;
z-index: 2;
}
.close:hover, .close:focus {
color: #999;
text-decoration: none;
cursor: pointer;
}
.modal-media {
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.actions button { margin-right: 5px; }
.media-placeholder {
display: flex;
align-items: center;
justify-content: center;
width: 200px;
height: 100px;
border: 1px solid #ddd;
background-color: #f9f9f9;
cursor: pointer;
}
.media-container {
position: relative;
width: 200px;
height: 100px;
}
.audio-player {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: none;
}
.audio-controls {
display: flex;
align-items: center;
margin-top: 5px;
}
.audio-controls button {
margin-right: 5px;
padding: 5px 10px;
}
.playlist {
margin-top: 10px;
max-height: 150px;
overflow-y: auto;
}
.playlist-item {
padding: 5px;
cursor: pointer;
border-bottom: 1px solid #eee;
}
.playlist-item.active {
background-color: #f0f0f0;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<!-- 消息提示 -->
<?php if (isset($message)): ?>
<div class="success"><?php echo $message; ?></div>
<?php endif; ?>
<?php if (isset($uploadMessage)): ?>
<div class="success"><?php echo $uploadMessage; ?></div>
<?php endif; ?>
<!-- 面包屑导航 -->
<div class="breadcrumbs">
<a href="<?php echo $_SERVER['PHP_SELF']; ?>">根目录</a>
<?php foreach ($breadcrumbs as $crumb): ?>
/
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?dir=<?php echo urlencode($crumb['path']); ?>"><?php echo htmlspecialchars($crumb['name']); ?></a>
<?php endforeach; ?>
</div>
<?php if (!$isAdmin): ?>
<div class="admin-panel">
<h3>管理员登录</h3>
<form method="post" action="">
<label for="password">密码:</label>
<input type="password" id="password" name="password" required>
<button type="submit">登录</button>
<?php if (isset($errorMessage)): ?>
<p class="error"><?php echo $errorMessage; ?></p>
<?php endif; ?>
</form>
</div>
<?php else: ?>
<div class="admin-panel">
<a href="?logout">退出登录</a>
<h3>新建目录</h3>
<form method="post" action="?dir=<?php echo urlencode($currentDir); ?>">
<input type="text" name="newDir" placeholder="目录名称" required>
<button type="submit">创建</button>
</form>
<h3>上传文件</h3>
<form method="post" action="?dir=<?php echo urlencode($currentDir); ?>" enctype="multipart/form-data">
<input type="file" name="files[]" multiple required>
<button type="submit">上传到当前目录</button>
</form>
</div>
<?php endif; ?>
<h2><?php echo $currentDir ? htmlspecialchars($currentDir) : '根目录'; ?></h2>
<table class="file-list">
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>大小</th>
<th>修改时间</th>
<th>预览</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $item): ?>
<tr>
<td>
<?php if ($item['type'] === 'dir'): ?>
<a href="?dir=<?php echo urlencode($item['path']); ?>"><?php echo htmlspecialchars($item['name']); ?>/</a>
<?php else: ?>
<?php echo htmlspecialchars($item['name']); ?>
<?php endif; ?>
</td>
<td><?php echo $item['type'] === 'dir' ? '目录' : '文件'; ?></td>
<td><?php echo $item['type'] === 'dir' ? '-' : formatSize($item['size']); ?></td>
<td><?php echo date('Y-m-d H:i:s', $item['mtime']); ?></td>
<td class="preview">
<?php if ($item['type'] === 'file'): ?>
<?php
$fileUrl = 'uploads/' . $item['path'];
$ext = strtolower($item['extension']);
if (in_array($ext, array('jpg', 'jpeg', 'png', 'gif'))) {
echo "<img src='$fileUrl' alt='图片预览' onclick=\"openImageModal('$fileUrl')\">";
} elseif (in_array($ext, array('mp4', 'webm', 'ogg'))) {
echo "<div class='media-placeholder' onclick=\"openVideoModal('$fileUrl', '$ext')\">";
echo "点击播放视频 <i class='material-icons'>play_arrow</i>";
echo "</div>";
} elseif (in_array($ext, array('mp3', 'wav', 'ogg'))) {
echo "<div class='media-container' data-path='{$item['path']}'>";
echo "<div class='media-placeholder' onclick=\"toggleAudio(this)\">";
echo "点击播放音频 <i class='material-icons'>play_arrow</i>";
echo "</div>";
echo "<div class='audio-player'>";
echo "<audio id='audio-{$item['path']}' controls preload='none'>";
echo "<source src='$fileUrl' type='audio/$ext'>";
echo "您的浏览器不支持音频播放";
echo "</audio>";
echo "<div class='audio-controls'>";
echo "<button onclick=\"changePlayMode('{$item['path']}')\" id='play-mode-{$item['path']}'>顺序播放</button>";
echo "<button onclick=\"playPrevious('{$item['path']}')\">上一首</button>";
echo "<button onclick=\"playNext('{$item['path']}')\">下一首</button>";
echo "</div>";
echo "<div class='playlist' id='playlist-{$item['path']}'>";
foreach ($audioFiles as $audio) {
$activeClass = ($audio['path'] === $item['path']) ? 'active' : '';
echo "<div class='playlist-item $activeClass' onclick=\"playAudio('{$audio['path']}')\">";
echo htmlspecialchars($audio['name']);
echo "</div>";
}
echo "</div>";
echo "</div>";
echo "</div>";
} else {
echo "-";
}
?>
<?php endif; ?>
</td>
<td class="actions">
<?php if ($isAdmin): ?>
<button onclick="openRenameModal('<?php echo $item['path']; ?>', '<?php echo htmlspecialchars($item['name']); ?>')">重命名</button>
<button onclick="openMoveModal('<?php echo $item['path']; ?>', '<?php echo htmlspecialchars($item['name']); ?>')">移动</button>
<button onclick="if(confirm('确定要删除吗?')) window.location='?dir=<?php echo urlencode($currentDir); ?>&action=delete&path=<?php echo urlencode($item['path']); ?>'">删除</button>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<!-- 图片查看模态框 -->
<div id="imageModal" class="modal">
<span class="close" onclick="closeImageModal()">×</span>
<div class="modal-content">
<img class="modal-media" id="modalImage">
</div>
</div>
<!-- 视频播放模态框 -->
<div id="videoModal" class="modal">
<span class="close" onclick="closeVideoModal()">×</span>
<div class="modal-content">
<video class="modal-media" controls autoplay></video>
</div>
</div>
<!-- 重命名模态框 -->
<div id="renameModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeRenameModal()">×</span>
<h3>重命名</h3>
<form method="post" action="?dir=<?php echo urlencode($currentDir); ?>">
<input type="hidden" id="renameOldPath" name="oldPath">
<input type="hidden" name="action" value="rename">
<p>新名称:<input type="text" id="renameNewName" name="newPath" required></p>
<button type="submit">确认</button>
<button type="button" onclick="closeRenameModal()">取消</button>
</form>
</div>
</div>
<!-- 移动模态框 -->
<div id="moveModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeMoveModal()">×</span>
<h3>移动</h3>
<form method="post" action="?dir=<?php echo urlencode($currentDir); ?>">
<input type="hidden" id="moveSourcePath" name="sourcePath">
<input type="hidden" name="action" value="move">
<p>文件:<span id="moveFileName"></span></p>
<p>目标目录:
<select id="moveTargetDir" name="targetPath" required>
<option value="">选择目录</option>
<?php foreach ($allDirs as $dir): ?>
<option value="<?php echo $dir . '/' . urlencode('__FILENAME__'); ?>"><?php echo $dir ?: '根目录'; ?></option>
<?php endforeach; ?>
</select>
</p>
<button type="submit">确认</button>
<button type="button" onclick="closeMoveModal()">取消</button>
</form>
</div>
</div>
</div>
<script>
// 存储播放模式:0-顺序播放,1-随机播放
var playModes = {};
// 图片查看模态框功能
function openImageModal(imgUrl) {
var modal = document.getElementById('imageModal');
var modalImage = document.getElementById('modalImage');
// 关闭其他模态框
closeVideoModal();
modal.style.display = 'block';
modalImage.src = imgUrl;
}
function closeImageModal() {
document.getElementById('imageModal').style.display = 'none';
}
// 视频播放模态框功能
function openVideoModal(videoUrl, ext) {
var modal = document.getElementById('videoModal');
var video = modal.querySelector('video');
// 关闭其他模态框
closeImageModal();
// 设置视频源
video.innerHTML = ''; // 清空现有源
var source = document.createElement('source');
source.src = videoUrl;
source.type = 'video/' + ext;
video.appendChild(source);
// 显示模态框并播放
modal.style.display = 'block';
video.load();
video.play().catch(function(e) {
console.log("自动播放失败:", e);
// 尝试手动触发播放
video.addEventListener('click', function() {
video.play();
});
});
}
function closeVideoModal() {
var modal = document.getElementById('videoModal');
var video = modal.querySelector('video');
// 暂停视频并清空源
video.pause();
video.innerHTML = '';
modal.style.display = 'none';
}
// 音频播放切换功能
function toggleAudio(placeholder) {
// 获取父容器和播放器
var container = placeholder.parentElement;
var player = container.querySelector('.audio-player');
var audio = player.querySelector('audio');
var path = container.dataset.path;
// 初始化播放模式
if (playModes[path] === undefined) {
playModes[path] = 0; // 默认顺序播放
}
// 更新播放模式按钮文本
document.getElementById('play-mode-' + path).textContent =
playModes[path] === 0 ? '顺序播放' : '随机播放';
// 隐藏所有其他音频播放器,停止所有音频
var allPlayers = document.querySelectorAll('.audio-player');
for (var i = 0; i < allPlayers.length; i++) {
var p = allPlayers[i];
if (p !== player) {
p.style.display = 'none';
var otherAudio = p.querySelector('audio');
if (otherAudio) otherAudio.pause();
}
}
// 显示所有其他占位符
var allPlaceholders = document.querySelectorAll('.media-placeholder');
for (var j = 0; j < allPlaceholders.length; j++) {
var ph = allPlaceholders[j];
if (ph !== placeholder) {
ph.style.display = 'flex';
}
}
if (player.style.display === 'none') {
// 隐藏占位符,显示播放器
placeholder.style.display = 'none';
player.style.display = 'block';
// 如果音频还没有加载,则加载并播放
if (audio.readyState === 0) {
audio.load();
}
// 尝试播放音频
audio.play().catch(function(e) {
console.log("自动播放失败:", e);
});
// 设置音频结束事件监听
audio.onended = function() {
playNext(path);
};
} else {
// 隐藏播放器,显示占位符
player.style.display = 'none';
placeholder.style.display = 'flex';
audio.pause();
}
}
// 切换播放模式
function changePlayMode(path) {
playModes[path] = playModes[path] === 0 ? 1 : 0;
var button = document.getElementById('play-mode-' + path);
button.textContent = playModes[path] === 0 ? '顺序播放' : '随机播放';
}
// 播放指定音频
function playAudio(path) {
// 找到对应的音频容器
var container = document.querySelector('.media-container[data-path="' + path + '"]');
if (!container) return;
var placeholder = container.querySelector('.media-placeholder');
toggleAudio(placeholder);
}
// 播放上一首
function playPrevious(path) {
var audioFiles = Array.prototype.slice.call(document.querySelectorAll('.media-container')).map(function(c) {
return c.dataset.path;
});
var currentIndex = audioFiles.indexOf(path);
if (currentIndex === -1) return;
var prevIndex;
if (currentIndex === 0) {
prevIndex = audioFiles.length - 1; // 第一首的上一首是最后一首
} else {
prevIndex = currentIndex - 1;
}
playAudio(audioFiles[prevIndex]);
}
// 播放下一首
function playNext(path) {
var audioFiles = Array.prototype.slice.call(document.querySelectorAll('.media-container')).map(function(c) {
return c.dataset.path;
});
var currentIndex = audioFiles.indexOf(path);
if (currentIndex === -1) return;
var nextIndex;
if (playModes[path] === 1) {
// 随机播放
do {
nextIndex = Math.floor(Math.random() * audioFiles.length);
} while (nextIndex === currentIndex && audioFiles.length > 1);
} else {
// 顺序播放
if (currentIndex === audioFiles.length - 1) {
nextIndex = 0; // 最后一首的下一首是第一首
} else {
nextIndex = currentIndex + 1;
}
}
playAudio(audioFiles[nextIndex]);
}
// 重命名模态框功能
function openRenameModal(path, name) {
var modal = document.getElementById('renameModal');
var oldPathInput = document.getElementById('renameOldPath');
var newNameInput = document.getElementById('renameNewName');
// 关闭其他模态框
closeImageModal();
closeVideoModal();
oldPathInput.value = path;
newNameInput.value = name;
// 生成新路径(自动替换文件名部分)
newNameInput.oninput = function() {
var pathParts = path.split('/');
pathParts[pathParts.length - 1] = this.value;
document.querySelector('input[name="newPath"]').value = pathParts.join('/');
};
modal.style.display = 'block';
}
function closeRenameModal() {
document.getElementById('renameModal').style.display = 'none';
}
// 移动模态框功能
function openMoveModal(path, name) {
var modal = document.getElementById('moveModal');
var sourcePathInput = document.getElementById('moveSourcePath');
var fileNameSpan = document.getElementById('moveFileName');
var targetDirSelect = document.getElementById('moveTargetDir');
// 关闭其他模态框
closeImageModal();
closeVideoModal();
sourcePathInput.value = path;
fileNameSpan.textContent = name;
// 为每个选项设置正确的文件名
var options = targetDirSelect.options;
for (var i = 0; i < options.length; i++) {
if (options[i].value) {
options[i].value = options[i].value.replace('__FILENAME__', name);
}
}
modal.style.display = 'block';
}
function closeMoveModal() {
document.getElementById('moveModal').style.display = 'none';
}
// 点击模态框外部关闭
window.onclick = function(event) {
var modals = [
document.getElementById('imageModal'),
document.getElementById('videoModal'),
document.getElementById('renameModal'),
document.getElementById('moveModal')
];
modals.forEach(function(modal) {
if (event.target === modal) {
// 关闭模态框时暂停媒体
if (modal.id === 'videoModal') {
var video = modal.querySelector('video');
video.pause();
video.innerHTML = '';
}
modal.style.display = 'none';
}
});
}
</script>
<?php
// 辅助函数:格式化文件大小
function formatSize($bytes) {
if ($bytes === 0) return '0 B';
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$i = floor(log($bytes, 1024));
return round($bytes / pow(1024, $i), 2) . ' ' . $units[$i];
}
?>
</body>
</html>