947740 Posted June 9, 2009 Share Posted June 9, 2009 I am having some trouble exporting a file as a csv. I have this code: <?php header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=file.csv"); header("Pragma: no-cache"); header("Expires: 0"); ?> And, in that file, there is this data: 1163 6/13/2009 162 10.36 944 6/13/2009 162 10.31 929 6/13/2009 162 10.33 1034 6/13/2009 162 7.44 But it is not working. Excel says it is not a valid .csv file. I have a feeling that the header content I am sending is not correct. What am I missing? Link to comment https://forums.phpfreaks.com/topic/161528-export-to-csv/ Share on other sites More sharing options...
MadTechie Posted June 9, 2009 Share Posted June 9, 2009 for a CSV your data should look like this "data1","data2" "12","34" "56","78" can you post some data in code tags, (or attach a file) as you maybe using a tab file Link to comment https://forums.phpfreaks.com/topic/161528-export-to-csv/#findComment-852408 Share on other sites More sharing options...
947740 Posted June 9, 2009 Author Share Posted June 9, 2009 I had copied that data from excel...the csv file has commas. I am going to try it with the quotes and see what happens. Link to comment https://forums.phpfreaks.com/topic/161528-export-to-csv/#findComment-852415 Share on other sites More sharing options...
947740 Posted June 9, 2009 Author Share Posted June 9, 2009 It worked. Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/161528-export-to-csv/#findComment-852422 Share on other sites More sharing options...
Mark Baker Posted June 9, 2009 Share Posted June 9, 2009 try header("Content-type: text/plain"); or header("Content-type: text/csv"); I had copied that data from excel...the csv file has commas. That's what the C in CSV stands for Link to comment https://forums.phpfreaks.com/topic/161528-export-to-csv/#findComment-852424 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.