L'errore "La pagina richiesta non è stata trovata" indica che l'URL di File Station generato non è corretto per il tuo sistema Synology. Ecco lo script corretto che mantiene il formato URL originale e gestisce meglio la configurazione:
php
<?php
// Configurazione del Database (DA MODIFICARE)
$db_host = 'localhost';
$db_user = 'db_audio_user';
$db_pass = 'LaTuaPasswordForte';
$db_name = 'audio_db';
// **CONFIGURA QUESTI 5 PERCORSI BASE DEL NAS**
define('NAS_BASE_PATH_1', '/volume1/millemusiche');
define('NAS_BASE_PATH_2', '/volume1/milleinterpreti');
define('NAS_BASE_PATH_3', '/volume1/ECM.Collection');
define('NAS_BASE_PATH_4', '/volume1/millemusiche.da.organizzare.2024');
define('NAS_BASE_PATH_5', '/volumeUSB1/usbshare');
// **CONFIGURA LA PORTA HTTPS DEL TUO NAS** (modifica se necessario)
define('NAS_HTTPS_PORT', '5001'); // Porta standard DSM è 5001, alcune installazioni usano 12001
// Mappa dei percorsi base
$nas_base_paths = [
'millemusiche' => NAS_BASE_PATH_1,
'milleinterpreti' => NAS_BASE_PATH_2,
'ecm.collection' => NAS_BASE_PATH_3,
'millemusiche.da.organizzare.2024' => NAS_BASE_PATH_4,
'usbshare' => NAS_BASE_PATH_5
];
// Determina il percorso base in base al primo segmento del full_path
function getNasBasePath($full_path) {
global $nas_base_paths;
$segments = explode('/', ltrim($full_path, '/'));
$first_segment = strtolower($segments[0] ?? '');
// Cerca una corrispondenza esatta o parziale
foreach ($nas_base_paths as $key => $path) {
if ($first_segment === strtolower($key) ||
strpos(strtolower($first_segment), strtolower($key)) === 0) {
return $path;
}
}
return NAS_BASE_PATH_1; // Default al primo percorso
}
// 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 corretta per generare link File Station (formato originale, sempre HTTPS)
function generateFolderLink($full_path, $nas_base_path) {
// Costruisci il percorso completo sul NAS
$real_path = $nas_base_path;
if ($full_path !== '/' && $full_path !== '') {
$real_path .= '/' . ltrim($full_path, '/');
}
// Ottieni l'hostname senza porta
$host = $_SERVER['HTTP_HOST'];
if (strpos($host, ':') !== false) {
$host = explode(':', $host)[0];
}
// Usa sempre HTTPS con la porta configurata
$https_port = NAS_HTTPS_PORT;
// Codifica il percorso per l'URL (formato originale che funzionava)
$encoded_path = urlencode($real_path);
// Costruisci l'URL di File Station nel formato originale
$file_station_url = "https://$host:$https_port";
$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 alternativa per DSM 7.x (se quella sopra non funziona)
function generateFolderLinkDSM7($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];
}
$https_port = NAS_HTTPS_PORT;
$encoded_path = rawurlencode($real_path);
// Formato per DSM 7.x
return "https://$host:$https_port/filestation/index.cgi?launchApp=SYNO.SDS.FileStation.Application&openfile=" . $encoded_path;
}
?>
<!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>
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; }
.config-info {
background-color: #e7f3ff;
border: 1px solid #b8daff;
padding: 10px;
margin-bottom: 20px;
border-radius: 4px;
font-size: 0.9em;
}
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;
cursor: pointer;
border: none;
}
.folder-link:hover { background-color: #0056b3; }
.folder-link.alternative { background-color: #28a745; }
.folder-link.alternative:hover { background-color: #1e7e34; }
.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>🎵 MILLEMUSICHE DB</h1>
<div class="config-info">
<strong>ℹ️ Configurazione attuale:</strong><br>
Porta HTTPS: <?php echo NAS_HTTPS_PORT; ?> |
Host: <?php echo $_SERVER['HTTP_HOST']; ?><br>
<small>Se i link non funzionano, modifica la costante NAS_HTTPS_PORT nello script (riga 12)</small>
</div>
<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 per questa cartella
$nas_base_path = getNasBasePath($row['full_path']);
// Genera entrambi i tipi di link per massima compatibilità
$file_station_link = generateFolderLink($row['full_path'], $nas_base_path);
$file_station_link_dsm7 = generateFolderLinkDSM7($row['full_path'], $nas_base_path);
// Percorso completo nel sistema
$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 (DSM 6.x)</span>
</a>
<a href="<?php echo htmlspecialchars($file_station_link_dsm7); ?>"
target="_blank"
class="folder-link alternative tooltip">
📂 DSM 7.x
<span class="tooltiptext">Apri in File Station (DSM 7.x)</span>
</a>
<button onclick="copyToClipboard('<?php echo htmlspecialchars(addslashes($full_system_path)); ?>')"
class="folder-link 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.currentTarget;
const originalText = button.innerHTML;
button.innerHTML = '✅ Copiato!';
button.style.backgroundColor = '#28a745';
setTimeout(() => {
button.innerHTML = originalText;
button.style.backgroundColor = '#007bff';
}, 2000);
} catch (err) {
alert('Impossibile copiare automaticamente. Percorso: ' + text);
}
document.body.removeChild(tempInput);
}
</script>
</body>
</html>
Principali Correzioni:
Formato URL originale: Ho ripristinato il formato URL di File Station che funzionava nel tuo script originale.
Configurazione porta facilmente modificabile: Ho aggiunto la costante NAS_HTTPS_PORT in cima al file che puoi facilmente modificare se la tua porta non è 5001.
Due versioni di link: Ho incluso entrambe le versioni (DSM 6.x e DSM 7.x) così puoi testare quale funziona con il tuo sistema.
Informazioni di debug: Ho aggiunto un box informativo che mostra la configurazione attuale.
Miglior gestione dei percorsi: Ho migliorato la logica di riconoscimento dei percorsi base.
Come Procedere:
Modifica la porta se necessario: Se il tuo NAS non usa la porta 5001 per HTTPS, modifica la riga 12:
php
define('NAS_HTTPS_PORT', '12001'); // Cambia con la tua porta
Testa entrambi i pulsanti: Quando fai una ricerca, vedrai due pulsanti:
"📁 File Station" (formato DSM 6.x)
"📂 DSM 7.x" (formato DSM 7.x)
Prova entrambi per vedere quale funziona con il tuo sistema.
Verifica la configurazione: L'interfaccia ora mostra la porta e l'host utilizzati, così puoi verificare che siano corretti.
Se nessuno dei due formati funziona, fammelo sapere e ti aiuterò a identificare il formato URL corretto per il tuo specifico sistema Synology.