Here you lost the check that handle is not false.
I suggest something of the like:

```php
if( file_exists( $filepath ) && $file = fopen( $filepath, 'wb' ) )
{
    ...
}
```