You are here

function imce_delete_filepath in IMCE 7

Same name and namespace in other branches
  1. 6.2 inc/imce.page.inc \imce_delete_filepath()

Deletes a file by uri.

1 call to imce_delete_filepath()
imce_delete_file in inc/imce.page.inc
Deletes a file in the file list.

File

inc/imce.page.inc, line 465
Implements the file browser.

Code

function imce_delete_filepath($uri) {
  $file = file_load_multiple(array(), array(
    'uri' => $uri,
  ));
  $file = reset($file);

  // File exists in database.
  if ($file) {
    $usage = file_usage_list($file);
    $is_imce = isset($usage['imce']);
    unset($usage['imce']);

    // File is in use by an other module.
    if (!empty($usage)) {
      drupal_set_message(t('%filename is in use by another application.', array(
        '%filename' => $file->filename,
      )), 'error');
      return FALSE;
    }

    // Force delete file. Prevent running file_usage_list() second time.
    if (!file_delete($file, TRUE)) {
      return FALSE;
    }
  }
  elseif (!file_unmanaged_delete($uri)) {
    return FALSE;
  }
  return TRUE;
}