Ecco lo script PHP modificato con 4 variabili NAS_BASE_PATH che potrai personalizzare. Ho anche aggiunto dei commenti per aiutarti a capire cosa modificare.
php
<?php
// Configurazione del Database (MODIFICA QUESTI VALORI)
$db_host = 'localhost'; // Il database è sul NAS stesso
$db_user = 'db_audio_user';
$db_pass = 'LaTuaPasswordForte';
$db_name = 'audio_db';
// **CONFIGURA QUESTI 4 PERCORSI BASE DEL NAS**
// Sono i percorsi fisici dove risiedono le cartelle audio sul tuo NAS
define('NAS_BASE_PATH_1', '/volume1/Music'); // Esempio: Cartella principale audio
define('NAS_BASE_PATH_2', '/volume1/AudioBooks'); // Esempio: Cartella audiolibri
define('NAS_BASE_PATH_3', '/volume2/Podcast'); // Esempio: Cartella podcast
define('NAS_BASE_PATH_4', '/volume1/Archivio'); // Esempio: Cartella archivio storico
// URL di base per File Station (non modificare, si adatta automaticamente)
$file_station_url = 'http://' . $_SERVER['HTTP_HOST'] . ':5000';
// Mappa dei percorsi base per decidere quale usare (MODIFICA SE NECESSARIO)
$nas_base_paths = [
'music' => NAS_BASE_PATH_1,
'audiobooks' => NAS_BASE_PATH_2,
'podcast' => NAS_BASE_PATH_3,
'archivio' => NAS_BASE_PATH_4,
];
// Determina il percorso base in base al contesto (puoi personalizzare la logica)
function getNasBasePath($full_path) {
global $nas_base_paths;
// Esempio di logica: in base al primo segmento del percorso
$segments = explode('/', ltrim($full_path, '/'));
$first_segment = strtolower($segments[0] ?? '');
return $nas_base_paths[$first_segment] ?? NAS_BASE_PATH_1; // Default su Music
}
// Connessione al Database
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
// Verifica connessione
if ($conn->connect_error) {
die("Connessione fallita: " . $conn->connect_error);
}
$search_query = isset($_GET['q']) ? $conn->real_escape_string($_GET['q']) : '';
$results = [];
if ($search_query) {
// Cerca nel full_path o nel folder_name (case-insensitive)
$sql = "SELECT id, full_path, folder_name, parent_path, depth, audio_file_count FROM folder_metadata
WHERE full_path LIKE '%$search_query%' OR folder_name LIKE '%$search_query%'
ORDER BY depth ASC, folder_name ASC LIMIT 100";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$results[] = $row;
}
}
}
$conn->close();
// Funzione per generare il link alla cartella
function generateFolderLink($full_path, $nas_base_path, $file_station_url) {
// Costruisce il percorso completo sul NAS
$real_path = $nas_base_path;
if ($full_path !== '/' && $full_path !== '') {
$real_path .= '/' . ltrim($full_path, '/');
}
// URL per File Station
$encoded_path = urlencode($real_path);
$file_station_link = $file_station_url . "/webman/3rdparty/FileStation/index.cgi?launchApp=SYNO.SDS.FileStation.Application&launchParam=openfile%3D%22" . $encoded_path . "%22";
return $file_station_link;
}
// Funzione per generare link SMB/CIFS
function generateSMBLink($full_path, $nas_ip, $nas_base_path) {
// Determina il nome condivisione SMB (es. "Music", "AudioBooks")
$base_name = basename($nas_base_path);
$smb_path = '\\\\' . $nas_ip . '\\' . $base_name;
if ($full_path !== '/' && $full_path !== '') {
$smb_path .= '\\' . str_replace('/', '\\', ltrim($full_path, '/'));
}
return $smb_path;
}
// Ottieni l'IP del NAS
$nas_ip = $_SERVER['HTTP_HOST'];
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Archivio Audio NAS</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; background-color: #f4f4f4; color: #333; }
.container { max-width: 1200px; margin: auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
h1 { text-align: center; color: #0056b3; }
form { display: flex; justify-content: center; margin-bottom: 20px; }
input[type="text"] { width: 70%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 16px; }
input[type="submit"] { padding: 10px 15px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; margin-left: 10px; }
input[type="submit"]:hover { background-color: #0056b3; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { border: 1px solid #ddd; padding: 10px; text-align: left; }
th { background-color: #e9e9e9; }
tr:nth-child(even) { background-color: #f9f9f9; }
.no-results { text-align: center; color: #666; margin-top: 30px; }
.full-path { font-size: 0.9em; color: #555; }
.folder-links { display: flex; gap: 10px; flex-wrap: wrap; }
.folder-link {
display: inline-block;
padding: 4px 8px;
background-color: #007bff;
color: white;
text-decoration: none;
border-radius: 3px;
font-size: 0.8em;
transition: background-color 0.3s;
}
.folder-link:hover { background-color: #0056b3; }
.folder-link.smb { background-color: #28a745; }
.folder-link.smb:hover { background-color: #1e7e34; }
.copy-btn {
background-color: #6c757d;
cursor: pointer;
border: none;
color: white;
padding: 4px 8px;
border-radius: 3px;
font-size: 0.8em;
}
.copy-btn:hover { background-color: #545b62; }
.path-cell { min-width: 300px; }
.tooltip { position: relative; display: inline-block; }
.tooltip .tooltiptext {
visibility: hidden;
width: 200px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -100px;
opacity: 0;
transition: opacity 0.3s;
font-size: 0.7em;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
</style>
</head>
<body>
<div class="container">
<h1>🎵 Archivio Audio NAS</h1>
<form action="" method="get">
<input type="text" name="q" placeholder="Cerca nome cartella o percorso..." value="<?php echo htmlspecialchars($search_query); ?>">
<input type="submit" value="🔍 Cerca">
</form>
<?php if ($search_query && empty($results)): ?>
<p class="no-results">Nessun risultato trovato per "<?php echo htmlspecialchars($search_query); ?>".</p>
<?php elseif (!empty($results)): ?>
<table>
<thead>
<tr>
<th>Nome Cartella</th>
<th>File Audio</th>
<th>Percorso e Azioni</th>
<th>Profondità</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $row): ?>
<?php
// Determina il percorso base corretto
$nas_base_path = getNasBasePath($row['full_path']);
$file_station_link = generateFolderLink($row['full_path'], $nas_base_path, $file_station_url);
$smb_path = generateSMBLink($row['full_path'], $nas_ip, $nas_base_path);
$full_system_path = $nas_base_path . ($row['full_path'] !== '/' ? '/' . ltrim($row['full_path'], '/') : '');
?>
<tr>
<td><strong><?php echo htmlspecialchars($row['folder_name']); ?></strong></td>
<td><?php echo htmlspecialchars($row['audio_file_count']); ?></td>
<td class="path-cell">
<div class="full-path" style="margin-bottom: 8px;">
<?php echo htmlspecialchars($row['full_path']); ?>
</div>
<div class="folder-links">
<a href="<?php echo htmlspecialchars($file_station_link); ?>"
target="_blank"
class="folder-link tooltip">
📁 File Station
<span class="tooltiptext">Apri in File Station del NAS</span>
</a>
<button onclick="copyToClipboard('<?php echo htmlspecialchars($smb_path, ENT_QUOTES); ?>')"
class="copy-btn tooltip">
📋 SMB
<span class="tooltiptext">Copia percorso SMB negli appunti</span>
</button>
<button onclick="copyToClipboard('<?php echo htmlspecialchars($full_system_path, ENT_QUOTES); ?>')"
class="copy-btn tooltip">
📋 Percorso
<span class="tooltiptext">Copia percorso completo negli appunti</span>
</button>
</div>
</td>
<td><?php echo htmlspecialchars($row['depth']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p class="no-results">Inserisci un termine di ricerca per iniziare.</p>
<?php endif; ?>
</div>
<script>
function copyToClipboard(text) {
const tempInput = document.createElement('input');
tempInput.value = text;
document.body.appendChild(tempInput);
tempInput.select();
tempInput.setSelectionRange(0, 99999);
try {
document.execCommand('copy');
const button = event.target;
const originalText = button.innerHTML;
button.innerHTML = '✅ Copiato!';
button.style.backgroundColor = '#28a745';
setTimeout(() => {
button.innerHTML = originalText;
button.style.backgroundColor = '#6c757d';
}, 2000);
} catch (err) {
alert('Impossibile copiare automaticamente. Percorso: ' + text);
}
document.body.removeChild(tempInput);
}
</script>
</body>
</html>