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ī:
HTMLcodice:<button type="button" id="download_file">Scarica!</button>
JAVASCRIPTcodice: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); } }); }); });
PHPcodice:$filedata = @file_get_contents("cartella/file_test.pdf"); echo $filedata;
Purtroppo non funziona.
Ho cercato un po' qua e līŋŊ sul web ma non riesco a trovare una soluzione.
Spero nel vostro aiuto.
Grazie.

Rispondi quotando
