From bcb622632e9de946b3ed859a11a3b71642152685 Mon Sep 17 00:00:00 2001 From: Mike Russell Date: Mon, 15 Aug 2016 17:05:55 -0400 Subject: [PATCH] Better Filename finder for File Responses --- src/Endpoint/Abstracts/GET/AbstractGetFileEndpoint.php | 2 +- src/Response/File.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Endpoint/Abstracts/GET/AbstractGetFileEndpoint.php b/src/Endpoint/Abstracts/GET/AbstractGetFileEndpoint.php index 91149ec..86461e1 100644 --- a/src/Endpoint/Abstracts/GET/AbstractGetFileEndpoint.php +++ b/src/Endpoint/Abstracts/GET/AbstractGetFileEndpoint.php @@ -23,7 +23,7 @@ public function __construct($url, array $options = array()){ parent::__construct($url, $options); } - public function configureResponse(){ + protected function configureResponse(){ $this->Response->setDestinationPath($this->downloadDir); parent::configureResponse(); } diff --git a/src/Response/File.php b/src/Response/File.php index 3691c20..bc332c4 100644 --- a/src/Response/File.php +++ b/src/Response/File.php @@ -62,7 +62,8 @@ protected function extractFileName(){ foreach (explode("\r\n", $this->headers) as $header) { if (strpos($header, 'filename')!==FALSE){ - $this->setFileName(substr($header, (strpos($header, "\"")+1), -1)); + $fileName = substr($header, (strpos($header, "=")+1), -1); + $this->setFileName($fileName); } } } @@ -73,6 +74,8 @@ protected function extractFileName(){ * @return self */ public function setFileName($fileName){ + $fileName = preg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $fileName); + $fileName = preg_replace("([\.]{2,})", '', $fileName); $this->fileName = $fileName; return $this; }