File operations problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
srirams
Forum Commoner
Posts: 36
Joined: Wed May 25, 2005 8:57 am
Location: India
Contact:

File operations problem

Post by srirams »

All,

I get the following message:
Warning: fread(): supplied argument is not a valid stream resource in C:\program files\Apache Group\Apache2\htdocs\filehandle2.php on line 4

Warning: fclose(): supplied argument is not a valid stream resource in C:\program files\Apache Group\Apache2\htdocs\filehandle2.php on line 5

The code is

<?
$myFile = "test.txt";
$fh = fopen($myfile, 'r');
$theData = fread($fh,3);
fclose($fh);
?>

I have verified that the file test.txt exists and has some text in that. But I don't know why the above error message is appearing.
Could someone else.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I'm pretty sure fopen returns NULL instead of a "resource". Might want to check if you (the script) has enough rights.
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Re: File operations problem

Post by wwwapu »

Remember case sensitivity of the variable names

Code: Select all

$myFile = "test.txt";// note F
$fh = fopen($myfile, 'r'); // note f
$theData = fread($fh,3);
fclose($fh);
Post Reply