0

i have a file called test.csv on my webserver and i like to download it:

<a href="test.csv">CSV Download</a>

But the file will be opend in a browser and not downloaded.

1

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.