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.

Связанные темы

▾ 2 функции вызывают file_check_location()

fileupload_view in developer/examples/fileupload.module
Implementation of hook_view.
file_create_path in includes/file.inc
Make sure the destination is a complete path and resides in the file system directory, if it is not prepend the file system directory.

Код

<?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;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему