public static function SaveFile($FileName, $FileContents, $Flags = VANILLA_FILE_PUT_FLAGS) {
   
      // Check that the folder exists and is writable
      $DirName = dirname($FileName);
      $FileBaseName = basename($FileName);
      if (!is_dir($DirName))
         throw new Exception(sprintf('Requested save operation [%1$s] could not be completed because target folder [%2$s] does not exist.',$FileBaseName,$DirName));
         
      if (!IsWritable($DirName))
         throw new Exception(sprintf('Requested save operation [%1$s] could not be completed because target folder [%2$s] is not writable.',$FileBaseName,$DirName));
         
      if (file_put_contents($FileName, $FileContents, $Flags) === FALSE)
         throw new Exception(sprintf('Requested save operation [%1$s] could not be completed!',$FileBaseName));

      return TRUE;
   }