Skip to content Skip to sidebar Skip to footer

Php Csv File As Download

i have a file called test.csv on my webserver and i like to download it: CSV Download But the file will be opend in a browser and not downloaded

Solution 1:

Create an .htaccess file and write this in it:

AddType application/octet-stream .csv

This should tell apache to force the browser to download the file instead of open it.

Solution 2:

here is the code,

$cfile = "path/to/filename.csv";
    header('Content-Type: text/csv; charset=utf-8');
    header('Content-Disposition: attachment; filename='filename.csv');
    @readfile($cfile);

put this one as a function and called this when you click the download.

Solution 3:

Unless the client has some sort of "parser", you are unable to do it by default.

You will have to create your own php service or otherwise, to echo the contents of the file.

Solution 4:

I think you have to set the Content Type check http://php.net/manual/en/function.header.php

Post a Comment for "Php Csv File As Download"