fornisco lo script sbagliato. Deve essere corretto in maniera tale che l'apertura in File Station avvenga tutto in https

// **CONFIGURA QUESTI 4 PERCORSI BASE DEL NAS**
define('NAS_BASE_PATH_1', '/volume1/millemusiche');     // Esempio: Cartella principale audio
define('NAS_BASE_PATH_2', '/volume1/milleinterpreti'); // Esempio: Cartella audiolibri
define('NAS_BASE_PATH_3', '/volume1/ECM.Collection');    // Esempio: Cartella podcast
define('NAS_BASE_PATH_4', '/volume1/millemusiche.da.organizzare.2024');   // Esempio: Cartella archivio storico
define('NAS_BASE_PATH_5', '/volumeUSB1/usbshare');   // Esempio: Cartella archivio storico


// Mappa dei percorsi base (modifica se necessario)
$nas_base_paths = [
    'millemusiche' => NAS_BASE_PATH_1,
    'milleinterpreti' => NAS_BASE_PATH_2,
    'ECM.Colelction' => 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] ?? '');
    
    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);

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, $file_station_url) {
    $real_path = $nas_base_path;
    if ($full_path !== '/' && $full_path !== '') {
        $real_path .= '/' . ltrim($full_path, '/');
    }

    $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;
}

// Ottieni l'IP del NAS (serve solo per costruire URL File Station)
$nas_ip = $_SERVER['HTTP_HOST'];
$file_station_url = 'https://' . $nas_ip . ':12001'; // Porta standard File Station
?>

<!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; }
        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; }
        .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>

        <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);
                        $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($full_system_path, ENT_QUOTES); ?>')" 
                                            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.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>