|
Posted by NC on 12/31/07 00:22
On Dec 29, 7:22 am, NN <NoN...@home.com> wrote:
>
> i tried the script and it works great!
> i have a question. i added a link to download the file created with
> the url of the file. when i run it on my wamp server i click on the
> link and it prompts me to save the file, when i run it on my web
> server the csv opens in the browser instead of prompting to save the
> file.
> any idea of how to solve this?
> does it have to do with the php.ini settings?
No, it has to do with HTTP headers Web servers send out before serving
actual data.
How do you solve this? By writing a script that would send the
appropriate headers and then dump the data. Let's assume that, in
line with the previous example, you have created a file called
data.csv. Now you can write a script that will serve this data and
suggest to the browser that the data is to be saved as data.csv rather
than viewed in the browser:
header('Content-type: application/vnd.ms-excel');
header('Content-disposition: attachment; filename=data.csv');
readfile('data.csv');
Note, however, the word "suggest" above; the browser may choose to
ignore the "Content-disposition:" header and still display data in
browser of save it under the script's name rather than as data.csv...
Cheers,
NC
Navigation:
[Reply to this message]
|