Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open CSV file in browser instead of being downloaded HTML

Tags:

html

php

Just wondering if there is a way to open the csv file in the browser instead of being downloaded?

My code:

<a href="Myfile.csv">Open</a>
like image 238
SMH Avatar asked Sep 27 '16 04:09

SMH


People also ask

How do I download a file instead of open in browser?

In most browsers, clicking on the link will open the file directly in the browser. But, if you add the download attribute to the link, it will tell the browser to download the file instead. The download attribute works in all modern browsers, including MS Edge, but not Internet Explorer.


2 Answers

You have to add the following header.

header ('Content-Type: text/csv');
like image 60
Naga Avatar answered Sep 27 '22 18:09

Naga


header ('Content-Type: text/csv');

OR

Set iframe and put your CSV file URL in it.

like image 34
Virb Avatar answered Sep 27 '22 19:09

Virb