From 41354525c97b98ea58f85a5e2d8023c7a9bb0694 Mon Sep 17 00:00:00 2001 From: mmjjb Date: Fri, 20 Jan 2017 14:23:49 +0100 Subject: [PATCH] Update URL function, with browser headers 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 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Intervention/Image/AbstractDecoder.php b/src/Intervention/Image/AbstractDecoder.php index 74e158ad..c4a4616d 100644 --- a/src/Intervention/Image/AbstractDecoder.php +++ b/src/Intervention/Image/AbstractDecoder.php @@ -61,6 +61,17 @@ abstract class AbstractDecoder */ public function initFromUrl($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)) { return $this->initFromBinary($data); }