使用fopen和fwrite PHP的问题

I'm having issues writing to the file VarLog.txt, It's not read only (In properties), I'm trying to write the Variable or SQL Query as a string in the logs file that I created, I also wrote a check to see if VarLog exists, and if it doesn't, make it. Here's the Code

   if (!file_exists( "VarLog.txt")) {
    $fh = fopen("VarLog.txt", 'w') or die("can't open file");
    fclose($fh);
}
function anti_injection($sql) {
   $fp = fopen("VarLog.txt", "a+");  
   $sql = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$sql);
   $sql = trim($sql);
   $sql = strip_tags($sql);
   $sql = addslashes($sql);
   fwrite($fp, "SQL Query/String: $sql"); 
   fclose($fp);
   return $sql;
}

An Example of a $_POST variable

anti_injection($_POST['email']);

The code itself doesn't present any errors, other than the first check if the file exists and creating it is redundant.

  1. Remove the file VarLog.txt if it exists to rule out ownership problems.
  2. Check what your working directory is. Your path right now isn't an absolute path, so files will be written relative to whatever the current working directory is (use getcwd() to find out what that path is, and check there).