You are here

function file_unmanaged_delete in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/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.

See also

file_delete()

file_unmanaged_delete_recursive()

Related topics

15 calls to file_unmanaged_delete()
ConfigController::downloadExport in core/modules/config/src/Controller/ConfigController.php
Downloads a tarball of the site configuration.
CssCollectionOptimizer::deleteAll in core/lib/Drupal/Core/Asset/CssCollectionOptimizer.php
Deletes all optimized asset collections assets.
File::preDelete in core/modules/file/src/Entity/File.php
Acts on entities before they are deleted and before hooks are invoked.
file_unmanaged_delete_recursive in core/includes/file.inc
Deletes all files and directories in the specified filepath recursively.
file_unmanaged_move in core/includes/file.inc
Moves a file to a new location without database changes or hook invocation.

... See full list

File

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

Code

function file_unmanaged_delete($path) {
  if (is_file($path)) {
    return drupal_unlink($path);
  }
  $logger = \Drupal::logger('file');
  if (is_dir($path)) {
    $logger
      ->error('%path is a directory and cannot be removed using file_unmanaged_delete().', array(
      '%path' => $path,
    ));
    return FALSE;
  }

  // Return TRUE for non-existent file, but log that nothing was actually
  // deleted, as the current state is the intended result.
  if (!file_exists($path)) {
    $logger
      ->notice('The file %path was not deleted because it does not exist.', array(
      '%path' => $path,
    ));
    return TRUE;
  }

  // We cannot handle anything other than files and directories. Log an error
  // for everything else (sockets, symbolic links, etc).
  $logger
    ->error('The file %path is not of a recognized type so it was not deleted.', array(
    '%path' => $path,
  ));
  return FALSE;
}