You are here

function file_delete_multiple in Drupal 8

Deletes files.

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

$fids: An array of file ids.

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

2 calls to file_delete_multiple()
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_delete in core/includes/file.inc
Deletes a file and its database record.

File

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

Code

function file_delete_multiple(array $fids) {
  @trigger_error('file_delete_multiple() 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);
  $storage = \Drupal::entityTypeManager()
    ->getStorage('file');
  $entities = $storage
    ->loadMultiple($fids);
  $storage
    ->delete($entities);
}