mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 22:10:45 +02:00
Apply locale-independent basename() to attachment filenames. New function added: utf8_basename(). (Bug #43335 - Patch by ocean=Yohsuke)
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9905 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -70,7 +70,7 @@ if (!extension_loaded('xml'))
|
||||
$pos = 0;
|
||||
$len = strlen($str);
|
||||
$ret = '';
|
||||
|
||||
|
||||
while ($pos < $len)
|
||||
{
|
||||
$ord = ord($str[$pos]) & 0xF0;
|
||||
@@ -252,7 +252,7 @@ else
|
||||
if (is_null($offset))
|
||||
{
|
||||
$ar = explode($needle, $str);
|
||||
|
||||
|
||||
if (sizeof($ar) > 1)
|
||||
{
|
||||
// Pop off the end of the string where the last match was made
|
||||
@@ -527,7 +527,7 @@ else
|
||||
$op = '^(?:' . $op . '.{' . $oy . '})';
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
// offset == 0; just anchor the pattern
|
||||
$op = '^';
|
||||
}
|
||||
@@ -560,7 +560,7 @@ else
|
||||
|
||||
$lx = (int) ($length / 65535);
|
||||
$ly = $length % 65535;
|
||||
|
||||
|
||||
// negative length requires a captured group
|
||||
// of length characters
|
||||
if ($lx)
|
||||
@@ -632,7 +632,7 @@ function utf8_str_split($str, $split_len = 1)
|
||||
{
|
||||
return array($str);
|
||||
}
|
||||
|
||||
|
||||
preg_match_all('/.{' . $split_len . '}|[^\x00]{1,' . $split_len . '}$/us', $str, $ar);
|
||||
return $ar[0];
|
||||
}
|
||||
@@ -1917,4 +1917,32 @@ function utf8_wordwrap($string, $width = 75, $break = "\n", $cut = false)
|
||||
return implode($break, $new_lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* UTF8-safe basename() function
|
||||
*
|
||||
* basename() has some limitations and is dependent on the locale setting
|
||||
* according to the PHP manual. Therefore we provide our own locale independant
|
||||
* basename function.
|
||||
*
|
||||
* @param string $filename The filename basename() should be applied to
|
||||
* @return string The basenamed filename
|
||||
*/
|
||||
function utf8_basename($filename)
|
||||
{
|
||||
// We always check for forward slash AND backward slash
|
||||
// because they could be mixed or "sneaked" in. ;)
|
||||
// You know, never trust user input...
|
||||
if (strpos($filename, '/') !== false)
|
||||
{
|
||||
$filename = utf8_substr($filename, utf8_strrpos($filename, '/') + 1);
|
||||
}
|
||||
|
||||
if (strpos($filename, '\\') !== false)
|
||||
{
|
||||
$filename = utf8_substr($filename, utf8_strrpos($filename, '\\') + 1);
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user