Re: fgets fails after fopen succeeds
| From: | Thomas Powell | Date: | Wed, 11 May 2005 02:42:16 +0000 |
| Subject: | Re: fgets fails after fopen succeeds | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-214890@lists.php.net to get a copy of this message | ||
Printing $fh printed a 1.
My original file mode was just "r", I changed to "r+" to see if I'd get
permissions problems. The file handle seems to be fine. fgets just doesn't
like it.
The 0 && !feof() was a "commenting out" of the for loop to prevent the fgets
from running so that I so print the $fh.
This is an adaptation of the following code, which works fine on another
Windows 2000/Apache setup. Irony is, the original code doesn't work when
ported. I think I'm missing something in setup or permissions.
<?
$page=$_GET['page'];
print 'new_pages/'.$page.'.txt';
$fh = fopen('./new_pages/'.$page.'.txt', 'rt');
?>
<ul>
<?
for ($line = fgets($fh); ! feof($fh); $line = fgets($fh)) {
$line = trim($line);
if(strlen($line) > 0) {
print '<li>' . $line ."</li>\n";
}
}
?>
</ul>
<?
fclose($fh);
?>