function file_field_delete_file

file_field_delete_file($item, $field, $entity_type, $id, $count = 1)

Decrements the usage count for a file and attempts to delete it.

This function only has an effect if the file being deleted is used only by File module.

Parameters

$item: The field item that contains a file array.

$field: The field structure for the operation.

$entity_type: The type of $entity.

$id: The entity ID which contains the file being deleted.

$count: (optional) The number of references to decrement from the object containing the file. Defaults to 1.

Return value

Boolean TRUE if the file was deleted, or an array of remaining references if the file is still in use by other modules. Boolean FALSE if an error was encountered.

File

modules/file/file.field.inc, line 357
Field module functionality for the File module.

Code

function file_field_delete_file($item, $field, $entity_type, $id, $count = 1) {
  // To prevent the file field from deleting files it doesn't know about, check
  // the file reference count. Temporary files can be deleted because they
  // are not yet associated with any content at all.
  $file = (object) $item;
  $file_usage = file_usage_list($file);
  if ($file->status == 0 || !empty($file_usage['file'])) {
    file_usage_delete($file, 'file', $entity_type, $id, $count);
    return file_delete($file);
  }

  // Even if the file is not deleted, return TRUE to indicate the file field
  // record can be removed from the field database tables.
  return TRUE;
}

© 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/modules!file!file.field.inc/function/file_field_delete_file/7.x