diff --git a/CHANGELOG.md b/CHANGELOG.md index 00d668aafc..766d9c4568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com) and this project adheres to [Semantic Versioning](https://semver.org). +# TBD - 1.29.7 + +### Deprecated + +- Drawing::setIsUrl is unneeded. The property is set when setPath determines whether path is a url. + +### Fixed + +- More context options may be needed for http(s) image. Backport of [PR #4276](https://github.com/PHPOffice/PhpSpreadsheet/pull/4276) + ## 1.29.6 - 2024-12-08 ### Fixed diff --git a/src/PhpSpreadsheet/Worksheet/Drawing.php b/src/PhpSpreadsheet/Worksheet/Drawing.php index ff5d80b54e..6cf382b2f0 100644 --- a/src/PhpSpreadsheet/Worksheet/Drawing.php +++ b/src/PhpSpreadsheet/Worksheet/Drawing.php @@ -123,8 +123,21 @@ public function setPath($path, $verifyFile = true, $zip = null) $this->isUrl = true; $ctx = null; // https://github.com/php/php-src/issues/16023 - if (substr($path, 0, 6) === 'https:') { - $ctx = stream_context_create(['ssl' => ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT]]); + // https://github.com/php/php-src/issues/17121 + if (preg_match('/^https?:/', $path) === 1) { + $ctxArray = [ + 'http' => [ + 'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36', + 'header' => [ + //'Connection: keep-alive', // unacceptable performance + 'Accept: image/*;q=0.9,*/*;q=0.8', + ], + ], + ]; + if (preg_match('/^https:/', $path) === 1) { + $ctxArray['ssl'] = ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT]; + } + $ctx = stream_context_create($ctxArray); } $imageContents = @file_get_contents($path, false, $ctx); if ($imageContents !== false) { @@ -195,6 +208,8 @@ public function getIsURL(): bool * Set isURL. * * @return $this + * + * @deprecated 3.7.0 not needed, property is set by setPath */ public function setIsURL(bool $isUrl): self {