fgets fails after fopen succeeds

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Summary:
fopen returns a file handle, yet fgets doesn't want to read it. I've scoured 
google, php.net <http://php.net>, phpfreaks, usenet, etc. It seems to work 
elsewhere.

My setup:
Apache 2.0.47
PHP/5.0.4
Windows 2000

The call:
make_link_list("index");

(the file exists for fopen(), and actually errors if I add characters to 
break it)

My Source Code:

<?php
function make_link_list($name="") {

print $_SERVER['DOCUMENT_ROOT'].'/outside/'.$name.'.txt';
?>
<ul>
<?
$fh=fopen($_SERVER['DOCUMENT_ROOT'].'/outside/'.$name.'.txt', 'r+') || 
die("Cannot open file"); 

for ($line = fgets($fh, 1000); 0 && ! feof($fh); $line = fgets($fh)) {
 $line = trim($line);
 if(strlen($line) > 0) {
 print '<li>' . $line ."</li>\n";
 }
}
?>
</ul>
<?
fclose($fh);
}
?

Output:
C:/Program Files/Apache Group/Apache2/htdocs/youmightbe/outside/index.txt 
   
   
   *Warning*: fgets(): supplied argument is not a valid stream resource 
   in *C:\Program Files\Apache 
   Group\Apache2\htdocs\youmightbe\outside.php* on line *11*
   

*Warning*: fclose(): supplied argument is not a valid stream resource
in *C:\Program
Files\Apache Group\Apache2\htdocs\youmightbe\outside.php* on line *20*

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux