W3cubDocs

/Drupal 8

protected function FileStorage::unlink

protected FileStorage::unlink($path)

Deletes files and/or directories in the specified path.

If the specified path is a directory the method will call itself recursively to process the contents. Once the contents have been removed the directory will also be removed.

Parameters

string $path: A string containing either a file or directory path.

Return value

bool TRUE for success or if path does not exist, FALSE in the event of an error.

File

core/lib/Drupal/Component/PhpStorage/FileStorage.php, line 225

Class

FileStorage
Stores the code as regular PHP files.

Namespace

Drupal\Component\PhpStorage

Code

protected function unlink($path) {
  if (file_exists($path)) {
    if (is_dir($path)) {
      // Ensure the folder is writable.
      @chmod($path, 0777);
      foreach (new \DirectoryIterator($path) as $fileinfo) {
        if (!$fileinfo->isDot()) {
          $this->unlink($fileinfo->getPathName());
        }
      }
      return @rmdir($path);
    }
    // Windows needs the file to be writable.
    @chmod($path, 0700);
    return @unlink($path);
  }
  // If there's nothing to delete return TRUE anyway.
  return TRUE;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!PhpStorage!FileStorage.php/function/FileStorage::unlink/8.1.x