[CORE][StoreRemoteMedia] Fixed bug where sometimes images were written outside the site root
This commit is contained in:
committed by
Diogo Cordeiro
parent
a38f25f7cd
commit
7070a14480
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user