From cc57d23b17784d396c17fb44efb13eb10eddf027 Mon Sep 17 00:00:00 2001 From: Jeroen Desloovere Date: Tue, 3 Jul 2018 14:12:18 +0200 Subject: [PATCH] Add fix for #75 and #79 Add fix for #75 and #79 If 'allow_url_fopen' is false on the hosting, we now have an alternative way to download the image. --- src/VCard.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/VCard.php b/src/VCard.php index abf8ee8..43b48e0 100644 --- a/src/VCard.php +++ b/src/VCard.php @@ -223,6 +223,7 @@ public function addRole($role) * @param string $url image url or filename * @param bool $include Do we include the image in our vcard or not? * @param string $element The name of the element to set + * @throws VCardException */ private function addMedia($property, $url, $include = true, $element) { @@ -251,7 +252,15 @@ private function addMedia($property, $url, $include = true, $element) $fileType = strtoupper(substr($mimeType, 6)); if ($include) { - $value = file_get_contents($url); + if ((bool) ini_get('allow_url_fopen') === true) { + $value = file_get_contents($url); + } else { + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + $value = curl_exec($curl); + curl_close($curl); + } if (!$value) { throw VCardException::emptyURL();