You are here

function file_delete in Drupal 8

Same name and namespace in other branches
  1. 4 includes/file.inc \file_delete()
  2. 5 includes/file.inc \file_delete()
  3. 6 includes/file.inc \file_delete()
  4. 7 includes/file.inc \file_delete()

Deletes a file and its database record.

Instead of directly deleting a file, it is strongly recommended to delete file usages instead. That will automatically mark the file as temporary and remove it during cleanup.

Parameters

$fid: The file id.

Deprecated

in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityStorageInterface::delete() instead.

See also

file_unmanaged_delete()

\Drupal\file\FileUsage\FileUsageBase::delete()

\Drupal\Core\Entity\EntityStorageInterface::delete()

https://www.drupal.org/node/3021663

Related topics

1 call to file_delete()
FileLegacyTest::testEntityLegacyCode in core/modules/file/tests/src/Kernel/FileLegacyTest.php
@expectedDeprecation file_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\file\Entity\File::loadMultiple(). See https://www.drupal.org/node/2266845 @expectedDeprecation file_load() is deprecated in…

File

core/includes/file.inc, line 778
API for handling file uploads and server file management.

Code

function file_delete($fid) {
  @trigger_error('file_delete() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \\Drupal\\Core\\Entity\\EntityStorageInterface::delete() instead. See https://www.drupal.org/node/3021663.', E_USER_DEPRECATED);
  return file_delete_multiple([
    $fid,
  ]);
}