diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 1e95779aa3..2b9bc5f0ea 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -1432,7 +1432,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet ); if (isset($images[$linkImageKey])) { $url = str_replace('xl/drawings/', '', $images[$linkImageKey]); - $objDrawing->setPath($url); + $objDrawing->setPath($url, false); } if ($objDrawing->getPath() === '') { continue; @@ -1525,7 +1525,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet ); if (isset($images[$linkImageKey])) { $url = str_replace('xl/drawings/', '', $images[$linkImageKey]); - $objDrawing->setPath($url); + $objDrawing->setPath($url, false); } if ($objDrawing->getPath() === '') { continue; diff --git a/src/PhpSpreadsheet/Worksheet/Drawing.php b/src/PhpSpreadsheet/Worksheet/Drawing.php index 71a808815a..bee049100d 100644 --- a/src/PhpSpreadsheet/Worksheet/Drawing.php +++ b/src/PhpSpreadsheet/Worksheet/Drawing.php @@ -109,7 +109,12 @@ public function setPath(string $path, bool $verifyFile = true, ?ZipArchive $zip } // Implicit that it is a URL, rather store info than running check above on value in other places. $this->isUrl = true; - $imageContents = @file_get_contents($path); + $ctx = null; + // https://github.com/php/php-src/issues/16023 + if (str_starts_with($path, 'https:')) { + $ctx = stream_context_create(['ssl' => ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT]]); + } + $imageContents = @file_get_contents($path, false, $ctx); if ($imageContents !== false) { $filePath = tempnam(sys_get_temp_dir(), 'Drawing'); if ($filePath) { diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/URLImageTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/URLImageTest.php index 4f7fa1e583..e715621d39 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xlsx/URLImageTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/URLImageTest.php @@ -12,8 +12,7 @@ class URLImageTest extends TestCase { - // https://github.com/readthedocs/readthedocs.org/issues/11615 - public function xtestURLImageSource(): void + public function testURLImageSource(): void { if (getenv('SKIP_URL_IMAGE_TEST') === '1') { self::markTestSkipped('Skipped due to setting of environment variable'); @@ -31,20 +30,14 @@ public function xtestURLImageSource(): void // Check if the source is a URL or a file path self::assertTrue($drawing->getIsURL()); self::assertSame('https://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png', $drawing->getPath()); - $imageContents = file_get_contents($drawing->getPath()); - self::assertNotFalse($imageContents); - $filePath = tempnam(sys_get_temp_dir(), 'Drawing'); - self::assertNotFalse($filePath); - self::assertNotFalse(file_put_contents($filePath, $imageContents)); - $mimeType = mime_content_type($filePath); - unlink($filePath); - self::assertNotFalse($mimeType); - $extension = File::mime2ext($mimeType); - self::assertSame('png', $extension); + self::assertSame(IMAGETYPE_PNG, $drawing->getType()); + self::assertSame(84, $drawing->getWidth()); + self::assertSame(44, $drawing->getHeight()); } + $spreadsheet->disconnectWorksheets(); } - public function xtestURLImageSourceNotFound(): void + public function testURLImageSourceNotFound(): void { if (getenv('SKIP_URL_IMAGE_TEST') === '1') { self::markTestSkipped('Skipped due to setting of environment variable'); @@ -56,6 +49,7 @@ public function xtestURLImageSourceNotFound(): void $worksheet = $spreadsheet->getActiveSheet(); $collection = $worksheet->getDrawingCollection(); self::assertCount(0, $collection); + $spreadsheet->disconnectWorksheets(); } public function testURLImageSourceBadProtocol(): void