You are here

function imce_delete_filepath in IMCE 6.2

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

Delete a file by path.

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

File

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

Code

function imce_delete_filepath($filepath) {
  $file = db_fetch_object(db_query("SELECT * FROM {files} WHERE filepath = '%s'", $filepath));

  //file exists in database
  if ($file) {

    //prevent imce returning ref count
    $file->imce_noref = TRUE;

    //check references
    $refs = array_filter(module_invoke_all('file_references', $file));

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

    //prepare deletion
    module_invoke_all('file_delete', $file);
    if (!file_delete($file->filepath)) {
      return FALSE;
    }
    db_query('DELETE FROM {files} WHERE fid = %d', $file->fid);
  }
  elseif (!file_delete($filepath)) {
    return FALSE;
  }
  return TRUE;
}