php - fread(): supplied argument is not a valid stream resource -
this driving me little mad, thought perhaps server config issue, have tried on different host , same issue.
i have narrowed down , created test script rule out
<?php $myfile = "test.txt"; $fh = fopen($myfile, 'r') || die("couln't open file"); if ( $fh == true ) { echo "file handle valid<br>"; } else { echo "file handle invalid<br>"; } $thedata = fread($fh, filesize($myfile)) || die("couldn't read file"); echo $thedata; fclose($fh)|| die("couldn't close file"); ?> when test.txt missing correctly die couldn't open file when test.txt there
warning: fread(): supplied argument not valid stream resource in
i have set test.txt 777 sure
i wrote double check, works fine
<?php $data = file_get_contents('test.txt'); echo $data; ?> hopefully can shed light on me.
$fh = fopen($myfile, 'r') || die("couln't open file"); you assigning boolean expression $fh, losing actual file handle in process. try changing above line to
($fh = fopen($myfile, 'r')) || die("couln't open file");
Comments
Post a Comment