Handling file_get_contents errors

When you load an image from an external source with file_get_contents you can handle any errors like this:

$imgContent = @file_get_contents('https:\\www.external.url\image.jpg');
    if ($imgContent === false) {
        echo json_encode([
           'success'  => false,
           'localUrl' => null,
           'message'  => 'Afbeelding kon niet worden opgehaald'

Adding the @ surpresses the error message and the statement itself returns the content or just false when not possible to get something.

Last update: Tue, 13 Sep 2022 14:32:15