-1
private function WriteFile($file,$mode,$content){
    $handle = fopen($file, $mode);
    fwrite($handle, $content);
    fclose($handle);
}

this is my code and giving me the error

fclose() expects parameter 1 to be resource, boolean given in and fwrite() expects parameter 1 to be resource, boolean given in directory

ADreNaLiNe-DJ
  • 4,787
  • 3
  • 26
  • 35

1 Answers1

3

This is because fopen fails to open your file: the error message indicates that a boolean is given instead of a resource.

From PHP documentation:

Returns a file pointer resource on success, or FALSE on error.

You should check the value of $handle.

$handle = fopen($file, $mode);
if(is_resource($handle)) {
    fwrite($handle, $content);
    fclose($handle);
} else {
    // Handle error if needed
}
ADreNaLiNe-DJ
  • 4,787
  • 3
  • 26
  • 35