Skip to content

Commit

Permalink
Better Filename finder for File Responses
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelJ2324 committed Aug 15, 2016
1 parent 5295d08 commit bcb6226
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Endpoint/Abstracts/GET/AbstractGetFileEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
5 changes: 4 additions & 1 deletion src/Response/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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;
}
Expand Down

0 comments on commit bcb6226

Please sign in to comment.