You are here

function file_unmanaged_delete in Drupal 8

Same name and namespace in other branches
  1. 7 includes/file.inc \file_unmanaged_delete()

Deletes a file without database changes or hook invocations.

This function should be used when the file to be deleted does not have an entry recorded in the files table.

Parameters

$path: A string containing a file path or (streamwrapper) URI.

Return value

TRUE for success or path does not exist, or FALSE in the event of an error.

Deprecated

in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\File\FileSystemInterface::delete().

See also

file_delete()

file_unmanaged_delete_recursive()

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

Related topics

1 call to file_unmanaged_delete()
FileSystemDeprecationTest::testDeprecatedUnmanagedFileDelete in core/tests/Drupal/KernelTests/Core/File/FileSystemDeprecationTest.php
@expectedDeprecation file_unmanaged_delete() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystemInterface::delete(). See https://www.drupal.org/node/3006851.

File

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

Code

function file_unmanaged_delete($path) {
  @trigger_error('file_unmanaged_delete() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \\Drupal\\Core\\File\\FileSystemInterface::delete(). See https://www.drupal.org/node/3006851.', E_USER_DEPRECATED);
  try {
    return \Drupal::service('file_system')
      ->delete($path);
  } catch (FileException $e) {
    return FALSE;
  }
}