function file_delete

×

Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
cis7 file.inc file_delete(stdClass $file, $force = FALSE)
cle7 file.inc file_delete(stdClass $file, $force = FALSE)
elmsmedia7 file.inc file_delete(stdClass $file, $force = FALSE)
icor7 file.inc file_delete(stdClass $file, $force = FALSE)
meedjum_blog7 file.inc file_delete(stdClass $file, $force = FALSE)
mooc7 file.inc file_delete(stdClass $file, $force = FALSE)

Deletes a file and its database record.

If the $force parameter is not TRUE, file_usage_list() will be called to determine if the file is being used by any modules. If the file is being used the delete will be canceled.

Parameters

$file: A file object.

$force: Boolean indicating that the file should be deleted even if the file is reported as in use by the file_usage table.

Return value

mixed TRUE for success, FALSE in the event of an error, or an array if the file is being used by any modules.

See also

file_unmanaged_delete()

file_usage_list()

file_usage_delete()

hook_file_delete()

Related topics

12 calls to file_delete()
entity_metadata_delete_file in sites/all/modules/ulmus/entity/modules/callbacks.inc
Callback to delete a file. Watch out to not accidentilly implement hook_file_delete().
FeedsFileFetcher::deleteFile in sites/all/modules/ulmus/feeds/plugins/FeedsFileFetcher.inc
Helper. Deletes a file.
file_field_delete_file in modules/file/file.field.inc
Decrements the usage count for a file and attempts to delete it.
file_managed_file_submit in modules/file/file.module
Form submission handler for upload / remove buttons of managed_file elements.
file_move in includes/file.inc
Moves a file to a new location and update the file's database entry.

... See full list

2 string references to 'file_delete'
file_delete_multiple in sites/all/modules/ulmus/file_entity/file_entity.file_api.inc
Delete multiple files.
file_entity_hook_info_alter in sites/all/modules/ulmus/file_entity/file_entity.module
Implements hook_hook_info_alter().

File

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

Code

function file_delete(stdClass $file, $force = FALSE) {
  if (!file_valid_uri($file->uri)) {
    if (($realpath = drupal_realpath($file->uri)) !== FALSE) {
      watchdog('file', 'File %file (%realpath) could not be deleted because it is not a valid URI. This may be caused by improper use of file_delete() or a missing stream wrapper.', array('%file' => $file->uri, '%realpath' => $realpath));
    }
    else {
      watchdog('file', 'File %file could not be deleted because it is not a valid URI. This may be caused by improper use of file_delete() or a missing stream wrapper.', array('%file' => $file->uri));
    }
    drupal_set_message(t('The specified file %file could not be deleted, because it is not a valid URI. More information is available in the system log.', array('%file' => $file->uri)), 'error');
    return FALSE;
  }

  // If any module still has a usage entry in the file_usage table, the file
  // will not be deleted, but file_delete() will return a populated array
  // that tests as TRUE.
  if (!$force && ($references = file_usage_list($file))) {
    return $references;
  }

  // Let other modules clean up any references to the deleted file.
  module_invoke_all('file_delete', $file);
  module_invoke_all('entity_delete', $file, 'file');

  // Make sure the file is deleted before removing its row from the
  // database, so UIs can still find the file in the database.
  if (file_unmanaged_delete($file->uri)) {
    db_delete('file_managed')->condition('fid', $file->fid)->execute();
    db_delete('file_usage')->condition('fid', $file->fid)->execute();
    return TRUE;
  }
  return FALSE;
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.