-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaudio.php
More file actions
61 lines (52 loc) · 2.32 KB
/
Copy pathaudio.php
File metadata and controls
61 lines (52 loc) · 2.32 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
<?php
require_once __DIR__ . '/config.php';
$pageTitle = 'Audio';
$activeNav = 'audio';
$pageJS = ['js/download-utils.js', 'js/group-toggle.js', 'js/selection.js', 'js/audio-app.js'];
$realRoot = realpath($FILES_ROOT);
$audioFiles = [];
if ($realRoot && is_dir($realRoot)) {
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($realRoot, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($iterator as $file) {
if (in_array(strtolower($file->getExtension()), ['wav', 'ogg', 'mp3'])) {
$relativePath = substr($file->getPathname(), strlen($realRoot) + 1);
$audioFiles[] = ['path' => $relativePath, 'size' => $file->getSize()];
}
}
usort($audioFiles, function($a, $b) {
return strnatcasecmp($a['path'], $b['path']);
});
}
function formatFileSize($bytes) {
if ($bytes < 1024) return $bytes . ' B';
if ($bytes < 1024 * 1024) return round($bytes / 1024, 1) . ' KB';
return round($bytes / (1024 * 1024), 1) . ' MB';
}
include __DIR__ . '/includes/header.php';
?>
<h2>Audio</h2>
<p class="root-path">Root: <code><?php echo htmlspecialchars($FILES_ROOT); ?></code></p>
<?php if (!empty($audioFiles)): ?>
<p class="file-count"><?php echo count($audioFiles); ?> audio file(s) found</p>
<div class="audio-list" id="audio-list">
<?php foreach ($audioFiles as $file): ?>
<?php $audioExt = strtolower(pathinfo($file['path'], PATHINFO_EXTENSION)); ?>
<div class="audio-item" data-file="<?php echo htmlspecialchars($file['path']); ?>" data-name="<?php echo htmlspecialchars(basename($file['path'])); ?>" data-ext="<?php echo $audioExt; ?>">
<button class="audio-play-btn" title="Play">▶</button>
<div class="audio-details">
<div class="audio-name"><?php echo htmlspecialchars(basename($file['path'])); ?></div>
<div class="audio-path"><?php echo htmlspecialchars(dirname($file['path']) === '.' ? '' : dirname($file['path'])); ?></div>
</div>
<div class="audio-size"><?php echo formatFileSize($file['size']); ?></div>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="empty-state">
<p>No audio files found.</p>
</div>
<?php endif; ?>
<?php include __DIR__ . '/includes/footer.php'; ?>