Magos Posted July 12, 2009 Share Posted July 12, 2009 I have a file streaming script (for downloads) that works fine except for textfiles. All carriage return (CR, 0x13) characters are removed. The file on the server has both carriage return (CR, 0x13) and line feed (LF, 0x10) which I confirmed with a hex editor but when streamed/downloaded the file only contains line feed (LF, 0x10). If this file is opened in notepad on windows all text appears on the same line and is totally unreadable. The file is opened with "rb" (binary) so no characters should be thrown away. Any ideas what might be wrong? $DefaultContentType = "application/octet-stream"; $ContentTypeList = array ( "txt" => "text/plain", "zip" => "application/zip", "pdf" => "application/pdf", "doc" => "application/msword", "xls" => "application/vnd.ms-excel", "ppt" => "application/vnd.ms-powerpoint", "exe" => "application/octet-stream", "gif" => "image/gif", "png" => "image/png", "jpg" => "image/jpeg", "jpeg" => "image/jpeg", "mp3" => "audio/mpeg", "wav" => "audio/x-wav", "mpeg" => "video/mpeg", "mpg" => "video/mpeg", "mpe" => "video/mpeg", "mov" => "video/quicktime", "avi" => "video/x-msvideo", ); $Connection = Connect(); AssertExistance($Connection, $FileName); IncreaseCount($Connection, $FileName); header("Content-Description: File Transfer"); header("Content-Type: " . (isset($ContentTypeList[$Extension]) ? $ContentTypeList[$Extension] : $DefaultContentType)); header("Content-Length: " . $FileSize); header("Content-Disposition: attachment; filename=\"" . $FileName . "\""); header("Content-Transfer-Encoding: binary"); $File = @fopen($FullFileName, "rb"); if($File) { //$D = fread($File, $FileSize); //print $D; fpassthru($File); @fclose($File); } Link to comment https://forums.phpfreaks.com/topic/165684-streaming-text-file-linebreaks-cr-disappears/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.