note 120366 deleted from function.file-get-contents by salathe
| From: | salathe@php.net | Date: | Mon, 21 Sep 2020 14:39:57 +0000 |
| Subject: | note 120366 deleted from function.file-get-contents by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215259@lists.php.net to get a copy of this message | ||
Note Submitter: lesssugar
----
Keep in mind that if you use a URL as the filename attribute, and the external resource is not
reachable, the function will not return FALSE but instead an exception will be thrown.
So, in this case, instead of doing this:
$content = file_get_contents('https://en.wikipedia.org/wiki/Cat#/media/File:Large_Siamese_cat_tosses_a_mouse.jpg');
if ($content === false) {
// Handle the error
}
Do this:
try {
$content = file_get_contents('https://en.wikipedia.org/wiki/Cat#/media/File:Large_Siamese_cat_tosses_a_mouse.jpg');
if ($content === false) {
// Handle the error
}
} catch (Exception $e) {
// Handle exception
}