[Solution found] Thank you all for your replies. I changed the button to a link and it is now working as it should.
I know this subject has been discussed over and over, I've been reading possible solutions the whole day but none solves my problem.I need to make a script to create a csv from mysql data and download the file to the default downloads browser's folder.As I prior said I have tried every possible solution found.I don't have issues in getting the data and putting it in a csv. I will post a simple example from one solution I found here.
<?php header("Content-Type: text/csv"); header("Content-Disposition: attachment; filename=file.csv"); function outputCSV($data) { $output = fopen("php://output", "w"); foreach ($data as $row) fputcsv($output, $row); fclose($output); } outputCSV(array( array("name 1", "age 1", "city 1"), array("name 2", "age 2", "city 2"), array("name 3", "age 3", "city 3") ));?>
If I put the filename in fopen, like fopen("filename.csv","w") it saves the file in the server. I need to download the file. I believe the problem is in the header. What should I do? Any help is welcomed.
I am using latest versions of xampp, php and trying it on Chrome.
Thank you.