[CORE][StoreRemoteMedia] Fixed bug where sometimes images were written outside the site root

This commit is contained in:
Miguel Dantas
2019-07-11 23:49:16 +01:00
committed by Diogo Cordeiro
parent a38f25f7cd
commit 7070a14480
7 changed files with 53 additions and 39 deletions

View File

@@ -402,4 +402,19 @@ class HTTPClient extends HTTP_Request2
} while ($maxRedirs);
return new GNUsocial_HTTPResponse($response, $this->getUrl(), $redirs);
}
public static function get_filename(string $url, array $headers = null) : string {
if ($headers === null) {
$head = (new HTTPClient())->head($url);
$headers = $head->getHeader();
$headers = array_change_key_case($headers, CASE_LOWER);
}
if (array_key_exists('content-disposition', $headers) &&
preg_match('/^.+; filename="(.+?)"$/', $headers['content-disposition'], $matches) === 1) {
return $matches[1];
} else {
common_log(LOG_INFO, "Couldn't determine filename for url: {$url}");
return _('Untitled attachment');
}
}
}