Skip to content
Advertisement

How do I force a link to download a document not preview it

I am generating a table of entries in a MySQL database using PHP. Each record references a document. I am putting a button link in the table to download the document for that record. The documents largely link to csv files. However, when clicking on them, it loads the csv file in the browser, but I want to force it to download the file when the button is clicked.

<a href="../../uploads/03/12/Y2 PTM 01 Sept 2019.csv" class="btn btn-sm btn-teal"><i class="fas fa-download mg-r-10"></i>Download</a>

Is there a way to make the button download the document and not load it in the browser? The files will always be .csv or .xlsx files.

Advertisement

Answer

Based on Joroen’s comment, in the linked page, there is something which says to use:

a href=”link name” download target=”_blank”

Which seems to work – in chrome at least.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement