Skip to content

Commit 54885f2

Browse files
committed
Additional Context Options for http(s) Image
Backport of PR #4276.
1 parent 01c4122 commit 54885f2

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com)
66
and this project adheres to [Semantic Versioning](https://semver.org).
77

8+
# TBD - 2.3.5
9+
10+
### Deprecated
11+
12+
- Drawing::setIsUrl is unneeded. The property is set when setPath determines whether path is a url.
13+
14+
### Fixed
15+
16+
- More context options may be needed for http(s) image. Backport of [PR #4276](https://github.com/PHPOffice/PhpSpreadsheet/pull/4276)
17+
818
## 2024-12-08 - 2.3.4
919

1020
### Fixed

src/PhpSpreadsheet/Worksheet/Drawing.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,21 @@ public function setPath(string $path, bool $verifyFile = true, ?ZipArchive $zip
111111
$this->isUrl = true;
112112
$ctx = null;
113113
// https://github.com/php/php-src/issues/16023
114-
if (str_starts_with($path, 'https:')) {
115-
$ctx = stream_context_create(['ssl' => ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT]]);
114+
// https://github.com/php/php-src/issues/17121
115+
if (str_starts_with($path, 'https:') || str_starts_with($path, 'http:')) {
116+
$ctxArray = [
117+
'http' => [
118+
'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',
119+
'header' => [
120+
//'Connection: keep-alive', // unacceptable performance
121+
'Accept: image/*;q=0.9,*/*;q=0.8',
122+
],
123+
],
124+
];
125+
if (str_starts_with($path, 'https:')) {
126+
$ctxArray['ssl'] = ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT];
127+
}
128+
$ctx = stream_context_create($ctxArray);
116129
}
117130
$imageContents = @file_get_contents($path, false, $ctx);
118131
if ($imageContents !== false) {
@@ -183,6 +196,8 @@ public function getIsURL(): bool
183196
* Set isURL.
184197
*
185198
* @return $this
199+
*
200+
* @deprecated 3.7.0 not needed, property is set by setPath
186201
*/
187202
public function setIsURL(bool $isUrl): self
188203
{

0 commit comments

Comments
 (0)