file_save_upload

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

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

Версии
5
file_save_upload($source, $dest = FALSE, $replace = FILE_EXISTS_RENAME)
6
file_save_upload($source, $validators = array(), $dest = FALSE, $replace = FILE_EXISTS_RENAME)

Saves a file upload to a new location. The source file is validated as a proper upload and handled as such.

Параметры

$source A string specifying the name of the upload field to save. This parameter will contain the resulting destination filename in case of success.

$dest A string containing the directory $source should be copied to, will use the temporary directory in case no other value is set.

$replace A boolean, set to TRUE if the destination should be replaced when in use, but when FALSE append a _X to the filename.

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

An object containing file info or 0 in case of error.

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

▾ 6 функции вызывают file_save_upload()

fileupload_submit in developer/examples/fileupload.module
Implementation of hook_submit().
hook_prepare in developer/hooks/node.php
Этот хук используется модулями, которые работают с нодами. Он вызывается после загрузки ноды, но перед тем, как нода будет отображена в форме добавления/редактирования.
hook_submit in developer/hooks/node.php
This is a hook used by node modules. It is called after validation has succeeded and before insert/update. It is used to for actions which must happen only if the node is to be saved. Usually, $node is changed in some way and then the actual saving of...
system_theme_settings in modules/system/system.module
Menu callback; display theme configuration for entire site and individual themes.
upload_save in modules/upload/upload.module
user_validate_picture in modules/user/user.module

Код

<?php
function file_save_upload($source, $dest = FALSE, $replace = FILE_EXISTS_RENAME) {
  // Make sure $source exists && is valid.
  if ($file = file_check_upload($source)) {

    // This should be refactored, file_check_upload has already
    // moved the file to the temporary folder.
    if (!$dest) {
      $dest = file_directory_temp();
      $temporary = 1;
      if (is_file($file->filepath)) {
        // If this file was uploaded by this user before replace the temporary copy.
        $replace = FILE_EXISTS_REPLACE;
      }
    }

    unset($_SESSION['file_uploads'][is_object($source) ? $source->source : $source]);
    if (file_move($file, $dest, $replace)) {
      if ($temporary) {
        $_SESSION['file_uploads'][is_object($source) ? $source->source : $source] = $file;
      }
      return $file;
    }
    return 0;
  }
  return 0;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

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