file_delete

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 file_delete($path)
drupal7 file_delete($file, $force = FALSE)

Delete a file and its database record.

If the $force parameter is not TRUE hook_file_references() will be called to determine if the file is being used by any modules. If the file is being used is the delete will be canceled.

see file_unmanaged_delete()

Übergabeparameter

$file A file object.

$force Boolean indicating that the file should be deleted even if hook_file_references() reports that the file is in use.

Rückgabewert

mixed TRUE for success, FALSE in the event of an error, or an array if the file is being used by another module. The array keys are the module's name and the values are the number of references.

See also

hook_file_references()

hook_file_delete()

Verwandte Themen

▾ 8 functions call file_delete()

FileDeleteTest::testNormal in modules/simpletest/tests/file.test
Try deleting a normal file (as opposed to a directory, symlink, etc).
file_move in includes/file.inc
Move a file to a new location and update the file's database entry.
hook_node_delete_revision in modules/node/node.api.php
A revision of the node is deleted.
system_cron in modules/system/system.module
Implementation of hook_cron().
upload_node_delete in modules/upload/upload.module
Implementation of hook_node_delete().
upload_node_delete_revision in modules/upload/upload.module
Implementation of hook_node_delete_revision().
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.

Code

includes/file.inc, line 745

<?php
function file_delete($file, $force = FALSE) {
  $file = (object) $file;

  // If any module returns a value from the reference hook, the file will not
  // be deleted from Drupal, but file_delete will return a populated array that
  // tests as TRUE.
  if (!$force && ($references = module_invoke_all('file_references', $file))) {
    return $references;
  }

  // Let other modules clean up any references to the deleted file.
  module_invoke_all('file_delete', $file);

  // Make sure the file is deleted before removing its row from the
  // database, so UIs can still find the file in the database.
  if (file_unmanaged_delete($file->filepath)) {
    db_delete('files')->condition('fid', $file->fid)->execute();
    return TRUE;
  }
  return FALSE;
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen