Wouldn't it make sense to move that part into the ` if (!file_exists($file))` part?