form_set_error($file->source, t('File upload error. Could not move uploaded file.'));
watchdog('file', 'Upload error. Could not move file %file to destination %destination.', array('%file' =>$file->filename, '%destination' =>$file->destination));
return0;
}
// If we made it this far it's safe to record this file in the database.
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
// Insert new record to the database.
drupal_write_record('files', $file);
_field_file_cache($file); // cache the file in order to minimize load queries