fix: dont read /etc if open_basedir #4502 (#4505)

This commit is contained in:
Dag 2025-04-01 01:15:59 +02:00 committed by GitHub
parent db42f2786c
commit 462c005f2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -175,24 +175,28 @@ function parse_mime_type($url)
'image' => 'image/*', 'image' => 'image/*',
'mp3' => 'audio/mpeg', 'mp3' => 'audio/mpeg',
]; ];
// '@' is used to mute open_basedir warning, see issue #818 // if-check to avoid excessive php errors about open_basedir restriction (#4502)
if (@is_readable('/etc/mime.types')) { $open_basedir = ini_get('open_basedir');
$file = fopen('/etc/mime.types', 'r'); if (! $open_basedir) {
while (($line = fgets($file)) !== false) { // '@' is used to mute open_basedir warning, see issue #818
$line = trim(preg_replace('/#.*/', '', $line)); if (@is_readable('/etc/mime.types')) {
if (!$line) { $file = fopen('/etc/mime.types', 'r');
continue; while (($line = fgets($file)) !== false) {
} $line = trim(preg_replace('/#.*/', '', $line));
$parts = preg_split('/\s+/', $line); if (!$line) {
if (count($parts) == 1) { continue;
continue; }
} $parts = preg_split('/\s+/', $line);
$type = array_shift($parts); if (count($parts) == 1) {
foreach ($parts as $part) { continue;
$mime[$part] = $type; }
$type = array_shift($parts);
foreach ($parts as $part) {
$mime[$part] = $type;
}
} }
fclose($file);
} }
fclose($file);
} }
} }