Exporting/downloading txt file - readfile(); problems - creating line breaks

Greetings,

I created a script to export member’s items into a tab-delimited txt file. The script works great, it escapes tabs and new lines and creates a perfect export.txt file.

Problem: I have another link so people can download the export.txt file onto their computers using:


    $file = "export-files/".$member.".txt";
    header('Content-Description: File Transfer');
    header('Content-Type: text/plain');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit();

When I download export.txt, it appears to have newly created line-breaks that are not found in the export.txt file on the server. Does anyone know why this happens and how to prevent this?

Thanks

Seems like if a line of about 1024 characters, a line break happens - only on my downloaded file though…

nevermind, figured it out. 1024 characters was the maximum length of a line in a txt file viewed on Notepad. It looked fine in the browser since it’s not Notepad.

In addition, "
" does not produce a new line in a text file, you must put in "\r
" when writing a txt file to recognize it as linebreak. This fixed the export, file did not re-import due to a single tab at the end of the last row.

So yeah, two characters “\r” and a TAB gave me an 8 hour awful waffle… At least I learned something about a topic I’ve never done before!

Thanks for looking!