TypeError thrown

fclose(): Argument #1 ($stream) must be of type resource, null given