Mi scuso per i problemi persistenti. Ecco una versione rivista dello script che include ulteriori verifiche e ottimizzazioni per garantire che funzioni correttamente:
<?php
// Configurazione del Database
$db_host = 'localhost';
$db_user = 'db_audio_user';
$db_pass = 'LaTuaPasswordForte';
$db_name = 'audio_db';
// Configurazione porta HTTPS
define('NAS_HTTPS_PORT', 5001);
// Mappa dei percorsi base
$nas_base_paths = [
'millemusiche' => '/volume1/millemusiche',
'milleinterpreti' => '/volume1/milleinterpreti',
'ecm.collection' => '/volume1/ECM.Collection',
'millemusiche.da.organizzare.2024' => '/volume1/millemusiche.da.organizzare.2024',
'usbshare' => '/volumeUSB1/usbshare',
];
// Funzione per determinare il percorso base
function getNasBasePath($full_path) {
global $nas_base_paths;
$segments = explode('/', ltrim($full_path, '/'));
$first_segment = strtolower($segments[0] ?? '');
return $nas_base_paths[$first_segment] ?? $nas_base_paths['millemusiche'];
}
// 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 10000";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$results[] = $row;
}
}
}
$conn->close();
// Funzione per generare link File Station
function generateFolderLink($full_path, $nas_base_path) {
$real_path = $nas_base_path;
if ($full_path !== '/' && $full_path !== '') {
$real_path .= '/' . ltrim($full_path, '/');
}
$host = $_SERVER['HTTP_HOST'];
if (strpos($host, ':') !== false) {
$host = explode(':', $host)[0];
}
$file_station_url = "https://$host:" . NAS_HTTPS_PORT . "/webman/3rdparty/FileStation/index.cgi?launchApp=SYNO.SDS.FileStation.Application&launchParam=openfile%3D%22" . urlencode($real_path) . "%22";
return $file_station_url;
}
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MILLEMUSICHE DB</title>
<style>
/* Stili CSS */
</style>
</head>
<body>
<div class="container">
<h1>MILLEMUSICHE DB</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
$nas_base_path = getNasBasePath($row['full_path']);
$file_station_link = generateFolderLink($row['full_path'], $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>
<a href="<?php echo htmlspecialchars($file_station_link); ?>" target="_blank" class="folder-link">📁 File Station</a>
<button onclick="copyToClipboard('<?php echo htmlspecialchars($full_system_path, ENT_QUOTES); ?>')">📋 Percorso</button>
</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');
alert('Percorso copiato negli appunti!');
} catch (err) {
alert('Impossibile copiare automaticamente. Percorso: ' + text);
}
document.body.removeChild(tempInput);
}
</script>
</body>
</html>
Verifica:
- Verifica la porta HTTPS: Assicurati che la porta HTTPS sia 5001 o modifica la costante
NAS_HTTPS_PORT se necessario.
- Verifica l'URL di File Station: Assicurati che l'URL di File Station sia generato correttamente.
- Testa il link: Clicca sul link di File Station per ogni cartella e verifica che si apra correttamente.
Se il problema persiste, potremmo dover esplorare altre soluzioni come:
- Utilizzare un proxy inverso per reindirizzare le richieste.
- Verificare le configurazioni di rete e di sicurezza del tuo NAS.
- Utilizzare un browser diverso per testare la compatibilità.
Fammi sapere se hai bisogno di ulteriore aiuto!