Also check for fwrite returning 0, see http://www.php.net/manual/en/function.fwrite.php#96951