From f87c7de1af0a501c4e4127b5176e3faf6d9e6ab4 Mon Sep 17 00:00:00 2001 From: mmjjb Date: Fri, 20 Jan 2017 14:25:05 +0100 Subject: [PATCH] Update AbstractDecoder.php Several image providers have detection for which user agent is being used. Since I had several times issue's with that images where unavailable for Intervention since an missing user agent, I decided to add this header to get rid of the problems. --- src/Intervention/Image/AbstractDecoder.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Intervention/Image/AbstractDecoder.php b/src/Intervention/Image/AbstractDecoder.php index 74e158ad..b5d78ca2 100644 --- a/src/Intervention/Image/AbstractDecoder.php +++ b/src/Intervention/Image/AbstractDecoder.php @@ -61,7 +61,18 @@ abstract class AbstractDecoder */ public function initFromUrl($url) { - if ($data = @file_get_contents($url)) { + + $options = array( + 'http' => array( + 'method'=>"GET", + 'header'=>"Accept-language: en\r\n". + "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2\r\n" + ) + ); + + $context = stream_context_create($options); + + if ($data = @file_get_contents($url, false, $context)) { return $this->initFromBinary($data); }