Skip to content

Commit

Permalink
[php:core] prevent garbled file name when URL upload
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Apr 27, 2022
1 parent 3c2cd7c commit def49cf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion php/elFinder.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3338,7 +3338,14 @@ protected function upload($args)
fclose($fp);
throw $e;
}
$_name = preg_replace('~^.*?([^/#?]+)(?:\?.*)?(?:#.*)?$~', '$1', rawurldecode($url));
if (strpos($url, '%') !== false) {
$url = rawurldecode($url);
}
if (is_callable('mb_convert_encoding') && is_callable('mb_detect_encoding')) {
$url = mb_convert_encoding($url, 'UTF-8', mb_detect_encoding($url));
}
$url = iconv('UTF-8', 'UTF-8//IGNORE', $url);
$_name = preg_replace('~^.*?([^/#?]+)(?:\?.*)?(?:#.*)?$~', '$1', $url);
// Check `Content-Disposition` response header
if (($headers = get_headers($url, true)) && !empty($headers['Content-Disposition'])) {
if (preg_match('/filename\*=(?:([a-zA-Z0-9_-]+?)\'\')"?([a-z0-9_.~%-]+)"?/i', $headers['Content-Disposition'], $m)) {
Expand Down

0 comments on commit def49cf

Please sign in to comment.