file_destination

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/file.inc, строка 294

Версии
6
file_destination($destination, $replace)

Determines the destination path for a file depending on how replacement of existing files should be handled.

Параметры

$destination A string specifying the desired path.

$replace Replace behavior when the destination file already exists.

  • FILE_EXISTS_REPLACE - Replace the existing file
  • FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique
  • FILE_EXISTS_ERROR - Do nothing and return FALSE.

Возвращаемое значение

The destination file path or FALSE if the file already exists and FILE_EXISTS_ERROR was specified.

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

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

file_copy in includes/file.inc
Копирует файл из одного места в другое. Эта мощная функция работает как расширенная версия функции copy(). Непосредственно перед копированием проверяет правильность $source и $dest и возможность чтения/записи. Копирование файла происходить только если $source и $dest не равны.
file_save_upload in includes/file.inc
Сохраняет загруженный файл в новое место. Исходный файл должен быть загружен и обработан.

Код

<?php
function file_destination($destination, $replace) {
  if (file_exists($destination)) {
    switch ($replace) {
      case FILE_EXISTS_RENAME:
        $basename = basename($destination);
        $directory = dirname($destination);
        $destination = file_create_filename($basename, $directory);
        break;

      case FILE_EXISTS_ERROR:
        drupal_set_message(t('The selected file %file could not be copied, because a file by that name already exists in the destination.', array('%file' => $destination)), 'error');
        return FALSE;
    }
  }
  return $destination;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

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