Ecco lo script modificato per gestire 4 diversi NAS_BASE_PATH. Ho aggiunto anche una logica per determinare quale percorso base usare:
<?php
// Configurazione del Database
$db_host = 'localhost';
$db_user = 'db_audio_user';
$db_pass = 'LaTuaPasswordForte';
$db_name = 'audio_db';
// Configurazione dei percorsi base (MODIFICA QUESTI VALORI con i tuoi percorsi)
$NAS_BASE_PATHS = [
'/volume1/Music1', // Primo percorso base
'/volume1/Music2', // Secondo percorso base
'/volume2/Music3', // Terzo percorso base
'/volume2/Music4' // Quarto percorso base
];
$FILE_STATION_URL = '/webman/3rdparty/FileStation/filestation.html';
// Funzione per trovare il percorso base corretto
function findCorrectBasePath($full_path) {
global $NAS_BASE_PATHS;
foreach ($NAS_BASE_PATHS as $base_path) {
if (file_exists($base_path . $full_path)) {
return $base_path;
}
}
// Se non trova una corrispondenza, usa il primo percorso come default
return $NAS_BASE_PATHS[0];
}
// Connessione al Database
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
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) {
$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()) {
// Trova il percorso base corretto per questo file/cartella
$base_path = findCorrectBasePath($row['full_path']);
$row['actual_path'] = $base_path . $row['full_path'];
// Genera l'URL per File Station
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http';
$row['file_station_link'] = $protocol . '://' . $_SERVER['HTTP_HOST'] .
$FILE_STATION_URL . '?path=' . rawurlencode($row['actual_path']);
// Aggiungi il percorso base usato per riferimento
$row['base_path_used'] = $base_path;
$results[] = $row;
}
}
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Archivio Audio Multi-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; }
.full-path a { color: #007bff; text-decoration: none; display: flex; align-items: center; }
.full-path a:hover { text-decoration: underline; }
.folder-icon { margin-right: 5px; }
.tooltip { position: relative; display: inline-block; }
.tooltip .tooltiptext {
visibility: hidden;
width: 160px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px;
opacity: 0;
transition: opacity 0.3s;
}
.tooltip:hover .tooltiptext { visibility: visible; opacity: 1; }
.base-path-indicator {
font-size: 0.8em;
color: #666;
background-color: #f0f0f0;
padding: 2px 5px;
border-radius: 3px;
margin-left: 5px;
}
</style>
</head>
<body>
<div class="container">
<h1>Archivio Audio Multi-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 Completo</th>
<th>Profondità</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $row): ?>
<tr>
<td><strong><?php echo htmlspecialchars($row['folder_name']); ?></strong></td>
<td><?php echo htmlspecialchars($row['audio_file_count']); ?></td>
<td class="full-path tooltip">
<a href="<?php echo htmlspecialchars($row['file_station_link']); ?>" target="_blank">
<span class="folder-icon">📂</span>
<?php echo htmlspecialchars($row['full_path']); ?>
<span class="base-path-indicator">
<?php echo htmlspecialchars(basename($row['base_path_used'])); ?>
</span>
</a>
<span class="tooltiptext">Apri in File Station</span>
</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>
</body>
</html>
Principali Modifiche:
- Array di Percorsi Base:
$NAS_BASE_PATHS = [
'/volume1/Music1', // Primo percorso base
'/volume1/Music2', // Secondo percorso base
'/volume2/Music3', // Terzo percorso base
'/volume2/Music4' // Quarto percorso base
];
Modifica questi percorsi con i tuoi percorsi effettivi.
- Funzione per Trovare il Percorso Base:
function findCorrectBasePath($full_path) {
global $NAS_BASE_PATHS;
foreach ($NAS_BASE_PATHS as $base_path) {
if (file_exists($base_path . $full_path)) {
return $base_path;
}
}
return $NAS_BASE_PATHS[0];
}
Questa funzione cerca il percorso base corretto per ogni file/cartella.
- Indicatore del Percorso Base:
Ho aggiunto un indicatore visuale che mostra quale percorso base viene utilizzato per ogni risultato.
Come Usare:
-
Modifica i Percorsi Base:
- Sostituisci i percorsi in
$NAS_BASE_PATHS con i tuoi percorsi effettivi
- Esempio:
$NAS_BASE_PATHS = [
'/volume1/MUSICA',
'/volume1/AUDIO',
'/volume2/COLLECTION',
'/volume3/ARCHIVE'
];
-
Verifica i Permessi:
- Assicurati che PHP abbia i permessi di lettura su tutti i percorsi configurati
- Verifica che l'utente web possa accedere a tutti i percorsi
-
Test:
- Cerca un file/cartella
- Verifica che il percorso base corretto venga mostrato accanto al percorso
- Clicca sul link per aprire la cartella in File Station
Lo script ora mostrerà anche quale volume/percorso base viene utilizzato per ogni risultato, rendendo più facile capire dove si trova effettivamente ogni cartella.