file_check_location
includes/file.inc, строка 275
- Версии
- 5 – 6
file_check_location($source, $directory = '')
Проверяет действительно ли файл существует внутри папки $directory
. Следует применять для проверки реального существавания файла во избежание уязвимостей
// Returns FALSE: file_check_location('/www/example.com/files/../../../etc/passwd', '/www/example.com/files');
Параметры
$source
A string set to the file to check.
$directory
A string where the file should be located.
Возвращаемое значение
0 for invalid path or the real path of the source.
Связанные темы
Код
<?php
function file_check_location($source, $directory = '') {
$check = realpath($source);
if ($check) {
$source = $check;
}
else {
// This file does not yet exist
$source = realpath(dirname($source)) .'/'. basename($source);
}
$directory = realpath($directory);
if ($directory && strpos($source, $directory) !== 0) {
return 0;
}
return $source;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии