wrwom Posted January 25, 2007 Share Posted January 25, 2007 I am working on a script that parses a text file, extracts some information, stores the extracted information in a database, and writes a csv file for downloading and reading into a separate program. A simple html form is used to allow the user to point to the text file on their local machine, then on submitting the form runs the code to read, parse and write the file, the name of the csv file is determined by the code and changes with each text file processed.Everything is working at this point except that when I use the headers in php to create the download file the cvs that is downloaded to the local machine includes the written csv file and below that all of the html from the page beginning with the DOCTYPE line and continuing through the final </html> tag. The html comes after the csv data. The csv file that is written to the server (currently localhost) is correct, containing only the csv data.I suspect that there is something missing or incorrect in the header statements in the script that is causing this, but being new to this and a definite amature at programming, I have been unable to determine the problem. The portion of the script that downloads the file is: [pre]//download the written file. header('Content-Type: application/csv');header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Lenght: filesize('$filename')");readfile($filename);[/pre] I am running this using a WAMP5 installation on a Windows XP machine.Thanks for any help,William Quote Link to comment https://forums.phpfreaks.com/topic/35685-file-download-includes-html/ Share on other sites More sharing options...
pradeepa Posted February 2, 2009 Share Posted February 2, 2009 Hello all iam also getting the same problem. can anyone help me please........... Quote Link to comment https://forums.phpfreaks.com/topic/35685-file-download-includes-html/#findComment-752374 Share on other sites More sharing options...
MadTechie Posted February 2, 2009 Share Posted February 2, 2009 add exit(); after the readfile Quote Link to comment https://forums.phpfreaks.com/topic/35685-file-download-includes-html/#findComment-752471 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.