46 |
46 |
protected function _validateFilename($filename)
|
47 |
47 |
{
|
48 |
48 |
// backup locale setting
|
49 |
|
$locale = setlocale(LC_ALL, 0);
|
|
49 |
//$locale = setlocale(LC_ALL, 0);
|
50 |
|
|
|
50 |
|
|
51 |
$originalLocales = explode(";", setlocale(LC_ALL, 0));
|
|
52 |
|
51 |
53 |
// change locale to multibyte character charset allowing characters like umlauts
|
52 |
54 |
// en_US.UTF8 should always be available
|
53 |
|
setlocale(LC_ALL, 'en_US.UTF8');
|
|
55 |
$own = setlocale(LC_ALL, 'en_US.UTF8');
|
54 |
|
|
|
56 |
|
55 |
57 |
if($filename !== basename((string)$filename))
|
56 |
58 |
{
|
57 |
59 |
throw new InvalidArgumentException('Filename "' . (string)$filename . '" is not valid');
|
58 |
60 |
}
|
59 |
|
|
|
61 |
|
60 |
|
// restore locale setting
|
61 |
|
setlocale(LC_ALL, $locale);
|
|
62 |
//Recover to the default setting
|
|
63 |
$skipConstants = array( //these will be returned by setlocale(LC_ALL, 0), but don't exist anymore.
|
|
64 |
'LC_PAPER',
|
|
65 |
'LC_NAME',
|
|
66 |
'LC_ADDRESS',
|
|
67 |
'LC_TELEPHONE',
|
|
68 |
'LC_MEASUREMENT',
|
|
69 |
'LC_IDENTIFICATION'
|
|
70 |
);
|
|
71 |
|
|
72 |
foreach ($originalLocales as $localeSetting) {
|
|
73 |
if (strpos($localeSetting, "=") !== false) {
|
|
74 |
list ($category, $locale) = explode("=", $localeSetting);
|
|
75 |
} else {
|
|
76 |
$category = LC_ALL;
|
|
77 |
$locale = $localeSetting;
|
|
78 |
}
|
|
79 |
|
|
80 |
if (!in_array($category, $skipConstants)) {
|
|
81 |
setlocale(constant($category), $locale); //Using strings is deprecated.
|
|
82 |
}
|
|
83 |
}
|
62 |
|
|
|
84 |
|
63 |
85 |
return $this;
|
64 |
86 |
}
|
65 |
87 |
}
|