Salve,
il mio obbiettivo sarebbe quello di rendere disponibile per il download un file, dinamicamente, senza visualizzare il link diretto alla posizione nel server.
I file che vorrei poter far scaricare sono del tipo: doc, docx, xls, xlsx, txt, csv, pdf, jpg, png

Ho pensato di fare cosī:


codice:
<button type="button" id="download_file">Scarica!</button>
HTML

codice:
jQuery(document).ready(function (e){
    jQuery('#download_file').on('click', function () {
    debugger;
        var TableID = jQuery(this).attr("table_id");
        var UserID = jQuery(this).attr("user_id");
        var Action = jQuery(this).attr("action");
        
        
        jQuery.ajax({
            url: 'https://nomedominio.it/cartella/download.php',
            method: 'GET',
            xhrFields: {
                responseType: 'blob'
            },
            
            success: function (data) {
                var a = document.createElement('a');
                var url = window.URL.createObjectURL(data);
                a.href = url;
                a.download = 'download.pdf';
                document.body.append(a);
                a.click();
                a.remove();
                window.URL.revokeObjectURL(url);
            }
        });
    });
});
JAVASCRIPT

codice:
$filedata = @file_get_contents("cartella/file_test.pdf");
echo $filedata;
PHP


Purtroppo non funziona.
Ho cercato un po' qua e līŋŊ sul web ma non riesco a trovare una soluzione.
Spero nel vostro aiuto.
Grazie.