file_create_filename

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

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

Версии
5 – 6
file_create_filename($basename, $directory)

Create a full file path from a directory and filename. If a file with the specified name already exists, an alternative will be used.

Параметры

$basename string filename

$directory string directory

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

▾ 4 функции вызывают file_create_filename()

theme_upload_attachments in modules/upload/upload.module
Отображение прикрепленных файлов в виде таблицы.
upload_menu in modules/upload/upload.module
Реализация hook_menu().
upload_nodeapi in modules/upload/upload.module
Implementation of hook_nodeapi().
_upload_form in modules/upload/upload.module

Код

<?php
function file_create_filename($basename, $directory) {
  $dest = $directory .'/'. $basename;

  if (file_exists($dest)) {
    // Destination file already exists, generate an alternative.
    if ($pos = strrpos($basename, '.')) {
      $name = substr($basename, 0, $pos);
      $ext = substr($basename, $pos);
    }
    else {
      $name = $basename;
    }

    $counter = 0;
    do {
      $dest = $directory .'/'. $name .'_'. $counter++ . $ext;
    } while (file_exists($dest));
  }

  return $dest;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

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