function drupal_unlink

7.x drupal_unlink($uri, $context = NULL)
8.x drupal_unlink($uri, $context = NULL)

Deletes a file.

PHP's unlink() is broken on Windows, as it can fail to remove a file when it has a read-only flag set.


$uri: A URI or pathname.

$context: Refer to

Return value

Boolean TRUE on success, or FALSE on failure.

See also


Related topics

8 calls to drupal_unlink()
DrupalLocalStreamWrapper::unlink in drupal/includes/
Support for unlink().
FileTransferLocal::removeDirectoryJailed in drupal/includes/filetransfer/
Removes a directory.
FileTransferLocal::removeFileJailed in drupal/includes/filetransfer/
Removes a file.
FileValidatorTest::testFileValidateImageResolution in drupal/modules/simpletest/tests/file.test
This ensures the resolution of a specific file is within bounds. The image will be resized if it's too large.
file_unmanaged_delete in drupal/includes/
Deletes a file without database changes or hook invocations.

... See full list


drupal/includes/, line 2273
API for handling file uploads and server file management.


function drupal_unlink($uri, $context = NULL) {
  $scheme = file_uri_scheme($uri);
  if ((!$scheme || !file_stream_wrapper_valid_scheme($scheme)) && (substr(PHP_OS, 0, 3) == 'WIN')) {
    chmod($uri, 0600);
  if ($context) {
    return unlink($uri, $context);
  else {
    return unlink($uri);