Skip to content

Commit

Permalink
Additional Context Options for http(s) Images
Browse files Browse the repository at this point in the history
Backport of PR #4276.
  • Loading branch information
oleibman committed Dec 13, 2024
1 parent 0859772 commit f6ee1f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions src/PhpSpreadsheet/Worksheet/Drawing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit f6ee1f2

Please sign in to comment.