From f60aa9f1cde7d3985097d02daea1772d13123b1e Mon Sep 17 00:00:00 2001 From: Graham McMicken Date: Tue, 25 Aug 2015 15:29:53 -0700 Subject: [PATCH 1/2] Add support for non-seekable streams Check stream meta "seekable" before issuing rewind, as to support additional stream types. --- src/FileDownload.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/FileDownload.php b/src/FileDownload.php index 5937279..dcebefa 100644 --- a/src/FileDownload.php +++ b/src/FileDownload.php @@ -78,8 +78,12 @@ public function sendDownload ($filename, $forceDownload = true) header("Content-Length: {$this->getFileSize()}"); @ob_clean(); - - rewind($this->filePointer); + + $meta = stream_get_meta_data($this->filePointer); + + if( $meta['seekable'] == true ) + rewind($this->filePointer); + fpassthru($this->filePointer); } @@ -159,4 +163,4 @@ public static function createFromString ($content) return new FileDownload($file); } -} \ No newline at end of file +} From 0d596bc5d9f240844902cc7c8cecf8dd47f27b90 Mon Sep 17 00:00:00 2001 From: Graham McMicken Date: Tue, 25 Aug 2015 15:51:14 -0700 Subject: [PATCH 2/2] Clean/Disable Output Buffering Use ob_end_clean() to clear/disable the output buffer as to not exhaust PHP memory for large files. --- src/FileDownload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FileDownload.php b/src/FileDownload.php index dcebefa..bee5124 100644 --- a/src/FileDownload.php +++ b/src/FileDownload.php @@ -77,7 +77,7 @@ public function sendDownload ($filename, $forceDownload = true) header("Content-Transfer-Encoding: binary"); header("Content-Length: {$this->getFileSize()}"); - @ob_clean(); + @ob_end_clean(); $meta = stream_get_meta_data($this->filePointer);