From 1f08f160adf4607ef31a86d064e031e0a6a68a20 Mon Sep 17 00:00:00 2001 From: ayacoo Date: Sat, 16 Oct 2021 18:11:03 +0200 Subject: [PATCH] [FEATURE] Ability to stream to an Amazon S3 bucket (#2326) Related #2249 --- CHANGELOG.md | 2 ++ src/PhpSpreadsheet/Writer/BaseWriter.php | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96cb58d8c5..eeb235d99b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org). - More flexibility in the StringValueBinder to determine what datatypes should be treated as strings [PR #2138](https://github.com/PHPOffice/PhpSpreadsheet/pull/2138) - Helper class for conversion between css size Units of measure (`px`, `pt`, `pc`, `in`, `cm`, `mm`). [PR #2152](https://github.com/PHPOffice/PhpSpreadsheet/issues/2145) - Allow Row height and Column Width to be set using different units of measure (`px`, `pt`, `pc`, `in`, `cm`, `mm`), rather than only in points or MS Excel column width units. [PR #2152](https://github.com/PHPOffice/PhpSpreadsheet/issues/2145) +- Ability to stream to an Amazon S3 bucket + [Issue #2249](https://github.com/PHPOffice/PhpSpreadsheet/issues/2249) ### Changed diff --git a/src/PhpSpreadsheet/Writer/BaseWriter.php b/src/PhpSpreadsheet/Writer/BaseWriter.php index 3b03cfc37e..ddd61113df 100644 --- a/src/PhpSpreadsheet/Writer/BaseWriter.php +++ b/src/PhpSpreadsheet/Writer/BaseWriter.php @@ -115,7 +115,12 @@ public function openFileHandle($filename): void return; } - $fileHandle = $filename ? fopen($filename, 'wb+') : false; + $mode = 'wb+'; + $scheme = parse_url($filename, PHP_URL_SCHEME); + if ($scheme === 's3') { + $mode = 'w'; + } + $fileHandle = $filename ? fopen($filename, $mode) : false; if ($fileHandle === false) { throw new Exception('Could not open file "' . $filename . '" for writing.'); }