file_save

Versions
7
file_save(stdClass $file)

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 also

hook_file_insert()

@see hook_file_update()

Parameters

$file A file object returned by file_load().

Return value

The updated file object.

Related topics

▾ 7 functions call file_save()

file_copy in includes/file.inc
Copy a file to a new location and adds a file record to the database.
file_move in includes/file.inc
Move a file to a new location and update the file's database entry.
file_save_data in includes/file.inc
Save a string to the specified destination and create a database file entry.
file_save_upload in includes/file.inc
Saves a file upload to a new location.
upload_save in modules/upload/upload.module
user_save in modules/user/user.module
Save changes to a user account or add a new user.
user_update_7004 in modules/user/user.install
Add the user's pictures to the {file} table and make them managed files.

Code

includes/file.inc, line 479

<?php
function file_save(stdClass $file) {
  $file->timestamp = REQUEST_TIME;
  $file->filesize = filesize($file->uri);

  if (empty($file->fid)) {
    drupal_write_record('file', $file);
    // Inform modules about the newly added file.
    module_invoke_all('file_insert', $file);
  }
  else {
    drupal_write_record('file', $file, 'fid');
    // Inform modules that the file has been updated.
    module_invoke_all('file_update', $file);
  }

  return $file;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.