fgets fails after fopen succeeds -- cleaned up for better digestion.

From: Date: Thu, 12 May 2005 15:55:18 +0000
Subject: fgets fails after fopen succeeds -- cleaned up for better digestion.
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-215052@lists.php.net to get a copy of this message
I removed the "r+", since that not my intended mode. File Handle is 1 after the fopen call. fgets, feof, and fclose fail on $fh. (So does fread, FWIW). The file exists. fopen fails if it is moved. *Code:* <?php function make_link_list($name="") { print './outside/'.$name.'.txt'; ?> <ul> <? $fh=fopen('./outside/'.$name.'.txt', 'r') || die("Cannot open file"); print "File Handle: ".$fh; for ($line = fgets($fh, 1000); ! feof($fh); $line = fgets($fh, 1000)) { if (!$line) break ; $line = trim($line); if(strlen($line) > 0) { print '<li>' . $line ."</li>\n"; } } ?> </ul> <? fclose($fh); } make_link_list("index"); ?> *Output:* ./outside/index.txt File Handle:1 *Warning*: fgets(): supplied argument is not a valid stream resource in *C:\Program Files\Apache Group\Apache2\htdocs\youmightbe\outside.php* on line *12* *Warning*: feof(): supplied argument is not a valid stream resource in *C:\Program Files\Apache Group\Apache2\htdocs\youmightbe\outside.php*on line *12* *Warning*: fclose(): supplied argument is not a valid stream resource in *C:\Program Files\Apache Group\Apache2\htdocs\youmightbe\outside.php* on line *22* **

« previous php.general (#215052) next »