Skip to content

Commit f6ee1f2

Browse files
committed
Additional Context Options for http(s) Images
Backport of PR #4276.
1 parent 0859772 commit f6ee1f2

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
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 - 1.29.7
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
## 1.29.6 - 2024-12-08
919

1020
### Fixed

src/PhpSpreadsheet/Worksheet/Drawing.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,21 @@ public function setPath($path, $verifyFile = true, $zip = null)
123123
$this->isUrl = true;
124124
$ctx = null;
125125
// https://github.com/php/php-src/issues/16023
126-
if (substr($path, 0, 6) === 'https:') {
127-
$ctx = stream_context_create(['ssl' => ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT]]);
126+
// https://github.com/php/php-src/issues/17121
127+
if (preg_match('/^https?:/', $path) === 1) {
128+
$ctxArray = [
129+
'http' => [
130+
'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',
131+
'header' => [
132+
//'Connection: keep-alive', // unacceptable performance
133+
'Accept: image/*;q=0.9,*/*;q=0.8',
134+
],
135+
],
136+
];
137+
if (preg_match('/^https:/', $path) === 1) {
138+
$ctxArray['ssl'] = ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT];
139+
}
140+
$ctx = stream_context_create($ctxArray);
128141
}
129142
$imageContents = @file_get_contents($path, false, $ctx);
130143
if ($imageContents !== false) {
@@ -195,6 +208,8 @@ public function getIsURL(): bool
195208
* Set isURL.
196209
*
197210
* @return $this
211+
*
212+
* @deprecated 3.7.0 not needed, property is set by setPath
198213
*/
199214
public function setIsURL(bool $isUrl): self
200215
{

0 commit comments

Comments
 (0)