raindrop
raindrop

Reputation: 523

php download csv file via web page

I am trying this simple code to download csv file via my web page but didn't work.

     <?PHP
      header('Content-Type: application/csv'); 
      header('Content-Disposition: attachment; filename=test.csv'); 
      header('Pragma: no-cache');
      echo readfile('test.csv'); 
      ?>

the error is "internet explorer can't find "csv_download.php" the file link on my web page

                 <a href="csv_download.php">Click here to download the "CSV" file</a>

anything missing?

Upvotes: 1

Views: 1556

Answers (1)

Matt S
Matt S

Reputation: 15394

Your PHP file is not at the URL you expect. Always set the full path where possible:

<a href="/csv_download.php">...

Upvotes: 3

Related Questions