You are here

function field_file_save_upload in FileField 6.2

Same name and namespace in other branches
  1. 6.3 field_file.inc \field_file_save_upload()

Save a file upload to a new location. The source file is validated as a proper upload and handled as such. By implementing hook_file($op = 'insert'), modules are able to act on the file upload and to add their own properties to the file.

The file will be added to the files table as a temporary file. Temporary files are periodically cleaned. To make the file permanent file call file_set_status() to change its status.

Parameters

$source: A string specifying the name of the upload field to save.

$validators: An optional, associative array of callback functions used to validate the file. The keys are function names and the values arrays of callback parameters which will be passed in after the user and file objects. The functions should return an array of error messages, an empty array indicates that the file passed validation. The functions will be called in the order specified.

$dest: A string containing the directory $source should be copied to. If this is not provided or is not writable, the temporary directory will be used.

$replace: A boolean indicating whether an existing file of the same name in the destination directory should overwritten. A false value will generate a new, unique filename in the destination directory.

Return value

An array containing the file information, or 0 in the event of an error.

1 call to field_file_save_upload()
_filefield_file_upload in ./filefield.widget.inc
Upload a file to the given field and delta (or try to, at least), and update the corresponding part of the form state with the new file data.

File

./field_file.inc, line 83
Common functionality for file handling CCK field modules.

Code

function field_file_save_upload($source, $validators = array(), $dest = FALSE, $replace = FILE_EXISTS_RENAME) {
  if (!($file = file_save_upload($source, $validators, $dest, $replace))) {
    return 0;
  }

  // Let modules add additional properties to the yet barebone file object.
  foreach (module_implements('file_insert') as $module) {
    $function = $module . '_file_insert';
    $function($file);
  }
  _field_file_cache($file);

  // cache the file in order to minimize load queries
  return (array) $file;
}