You are here

function imce_mkdir_unlink in IMCE Mkdir 6

Delete a file in recursive directory deletion.

1 call to imce_mkdir_unlink()
imce_mkdir_rmdir_recursive in ./imce_mkdir.inc
Recursive directory deletion

File

./imce_mkdir.inc, line 173

Code

function imce_mkdir_unlink($filepath) {
  if (function_exists('imce_delete_filepath')) {
    return 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;
}