You are here

function field_file_save_upload in FileField 6.3

Same name and namespace in other branches
  1. 6.2 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.

Return value

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

1 call to field_file_save_upload()
filefield_save_upload in ./filefield_widget.inc
Given a FAPI element, save any files that may have been uploaded into it.

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) {
  if (!($file = file_save_upload($source, $validators, $dest, FILE_EXISTS_RENAME))) {
    return 0;
  }
  if (!@chmod($file->filepath, 0664)) {
    watchdog('filefield', 'Could not set permissions on destination file: %file', array(
      '%file' => $file->filepath,
    ));
  }

  // 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;
}