php 5.3 fwrite() expects parameter 1 to be resource error
===

I am using wamp server. I try to write into the file but it is giving such error: "Warning: fwrite() expects parameter 1 to be resource, boolean given ". How can I solve it?

    $file = 'file.txt';  
    if (($fd = fopen($file, "a") !== false)) { 
      fwrite($fd, 'message to be written' . "\n");   
	  fclose($fd); 
    } 