file_save($file)
drupal/includes/file.inc, line 331
Save a file object to the database.
If the $file->fid is not set a new record will be added. Re-saving an existing file will not change its status.
@see hook_file_insert() @see hook_file_update()
$file A file object returned by file_load().
The updated file object.
| Name | Description |
|---|---|
| File interface | Common file handling functions. |
function file_save($file) {
$file = (object)$file;
$file->timestamp = REQUEST_TIME;
$file->filesize = filesize($file->filepath);
if (empty($file->fid)) {
drupal_write_record('files', $file);
// Inform modules about the newly added file.
module_invoke_all('file_insert', $file);
}
else {
drupal_write_record('files', $file, 'fid');
// Inform modules that the file has been updated.
module_invoke_all('file_update', $file);
}
return $file;
}