#22682 [Com]: Proplems with fread(), ftell() and fseek() and CRLF newlines

From: Date: Mon, 26 Apr 2004 22:45:24 +0000
Subject: #22682 [Com]: Proplems with fread(), ftell() and fseek() and CRLF newlines
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-58831@lists.php.net to get a copy of this message
ID: 22682 Comment by: frank at heuveltop dot nl Reported By: fbeyer at clickhand dot de Status: No Feedback Bug Type: Filesystem function related Operating System: Windows XP PHP Version: 4CVS-2003-04-28 (stable) New Comment: I run PHP as a Apache (2.0.48) module. I tried several methods but there is no way PHP will read "\r" from the file. The filepointer returned by ftell is getting out of sync. I do confirm all the symptoms that are stated above. Allthought I can build a workaround by counting lines and add the number of lines to ftell, I am worried about reading binary files like images by GD library. Previous Comments: ------------------------------------------------------------------------ [2003-11-28 15:32:18] alexey at ozerov dot de I still have a related bug on Windows XP using PHP 4.3.4. Sample: <? header("Content-type: text/plain"); ini_set("auto_detect_line_endings", true); // Doesn't matter $file=fopen(__FILE__,"rt"); // "t" doesn't matter too $linenumber=0; while ($file && $line=fgets($file, 65536)) { echo ("$linenumber: ".$line."\n"); fseek($file, ftell($file), SEEK_SET); $linenumber++; } fclose($file); ?> fseek() should not do anything but it _shifts_ the file pointer (as many bytes back as many "\r" are in the last read input) if I the __FILE__ has DOS encoded line breaks. As the result every line is followed by a blank line in the sample output. ------------------------------------------------------------------------ [2003-08-17 18:34:15] sniper@php.net No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Open". Thank you. ------------------------------------------------------------------------ [2003-08-12 19:41:45] sniper@php.net Please try using this CVS snapshot: http://snaps.php.net/php4-STABLE-latest.tar.gz For Windows: http://snaps.php.net/win32/php4-win32-STABLE-latest.zip ------------------------------------------------------------------------ [2003-05-11 08:28:04] moriyoshi@php.net As Wez pointed out above, this is a generic __setmode() issue. status: open => verified ------------------------------------------------------------------------ [2003-04-28 12:31:38] wez@php.net Related to Bug #22497 ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/22682 -- Edit this bug report at http://bugs.php.net/?id=22682&edit=1

« previous php.bugs (#58831) next »