简体   繁体   中英

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM