rxbanditboy1112 Posted January 20, 2008 Share Posted January 20, 2008 The download doesn't start and nothing appears on the screen. This happens in IE and Firefox. header("Content-type: text/plain"); header('Content-Disposition: inline; filename=$file_name.csv'); echo $data; The data and file name is created before. I have tried a number a bunch of different things with the header, but it is not working. I don't get it.... I also tried this: header('Pragma: no-cache'); header('Expires: 0'); header('Content-Type: text/x-csv'); header('Content-Disposition: attachment; filename=$file_name.csv'); header("Content-Transfer-Encoding: binary"); echo $data; Quote Link to comment https://forums.phpfreaks.com/topic/86960-trying-to-start-a-csv-file-download-using-headers-in-php/ Share on other sites More sharing options...
btherl Posted January 21, 2008 Share Posted January 21, 2008 Try double-quoting the filename. You can also try text/csv instead of text/x-csv. Not sure what difference that will make. Quote Link to comment https://forums.phpfreaks.com/topic/86960-trying-to-start-a-csv-file-download-using-headers-in-php/#findComment-444689 Share on other sites More sharing options...
Barand Posted January 21, 2008 Share Posted January 21, 2008 this has worked for me <?php $filename = 'xyz.csv'; header('Content-type: application/octet-stream'); header("Content-Disposition: attachment; filename=\"$filename\""); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past echo "A, 1, 2, 3\n"; echo "B, 4, 5, 6\n"; Quote Link to comment https://forums.phpfreaks.com/topic/86960-trying-to-start-a-csv-file-download-using-headers-in-php/#findComment-444697 Share on other sites More sharing options...
rxbanditboy1112 Posted January 21, 2008 Author Share Posted January 21, 2008 I tried: <?php $filename = 'xyz.csv'; header('Content-type: application/octet-stream'); header("Content-Disposition: attachment; filename=\"$filename\""); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past echo "A, 1, 2, 3\n"; echo "B, 4, 5, 6\n"; Now it works in firefox, but in IE it outputs to the browser rather than start a download. Quote Link to comment https://forums.phpfreaks.com/topic/86960-trying-to-start-a-csv-file-download-using-headers-in-php/#findComment-445323 Share on other sites More sharing options...
btherl Posted January 22, 2008 Share Posted January 22, 2008 Did you restart IE? You may need to clear the cache, as it remembers content types. Quote Link to comment https://forums.phpfreaks.com/topic/86960-trying-to-start-a-csv-file-download-using-headers-in-php/#findComment-445764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.