file_save
function file_save
file_save(stdClass $file)
Saves a file object to the database.
If the $file->fid is not set a new record will be added.
Parameters
$file: A file object returned by file_load().
Return value
The updated file object.
See also
Related topics
File
- includes/file.inc, line 599
- API for handling file uploads and server file management.
Code
function file_save(stdClass $file) { $file->timestamp = REQUEST_TIME; $file->filesize = filesize($file->uri); // Load the stored entity, if any. if (!empty($file->fid) && !isset($file->original)) { $file->original = entity_load_unchanged('file', $file->fid); } module_invoke_all('file_presave', $file); module_invoke_all('entity_presave', $file, 'file'); if (empty($file->fid)) { drupal_write_record('file_managed', $file); // Inform modules about the newly added file. module_invoke_all('file_insert', $file); module_invoke_all('entity_insert', $file, 'file'); } else { drupal_write_record('file_managed', $file, 'fid'); // Inform modules that the file has been updated. module_invoke_all('file_update', $file); module_invoke_all('entity_update', $file, 'file'); } // Clear internal properties. unset($file->original); // Clear the static loading cache. entity_get_controller('file')->resetCache(array($file->fid)); return $file; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!file.inc/function/file_save/7.x