Safely removes a file

@param string $file
@throws \RuntimeException When invalid file provided
@return boolean
181766
public static function rmfile($file)
    {
        if (is_file($file)) {
            return chmod($file, 0777) && unlink($file);
        } else {
            throw new RuntimeException(sprintf(
                'Invalid file path supplied "%s"', $file
            ));
        }
    }
965193
protected function _removeFile($file)
    {
        $_file = new File($file);

        if ($_file->exists()) {
            $_file->delete();

            $folder = $_file->folder();
            if (count($folder->find()) === 0) {
                $folder->delete();
            }
            return true;
        }
        return false;
    }
1021600
public function deleteFromDisk($file)
    {
        if (!is_array($file)) {
            $file = $this->get($file);
        }

        $result = null;
        $this->hook->attach('file.delete.disk.before', $file, $result, $this);

        if (isset($result)) {
            return (bool) $result;
        }

        if (empty($file['path'])) {
            return false;
        }

        $path = gplcart_file_absolute($file['path']);

        if (!is_file($path)) {
            return false;
        }

        $result = unlink($path);
        $this->hook->attach('file.delete.disk.after', $file, $result, $this);
        return $result;
    }
680010
public static function removeFile($file)
    {
        if (!is_readable($file) || !is_file($file)) {
            throw new Exception('No such file: ' . $file);
        }
        $res = unlink($file);
        if (false === $res) {
            throw new Exception('File deleting failure: ' . $file);
        }
        return $res;
    }
311379
private function removeFile(File $file)
	{
		$this->removeFileInFileSystem($file);

		if ($file instanceof Image) {
			$em = $this->getDoctrineEntityManager();
			$imageSizeCn = ImageSize::CN();
			$em->createQuery("DELETE FROM $imageSizeCn s WHERE s.master = :master")
				->setParameter('master', $file->getId())
				->execute();
		}

		$entityManager = $this->getDoctrineEntityManager();
		$entityManager->remove($file);
		$entityManager->flush();
	}
593804
public function rmFile($file)
    {

        if (!is_file($file)) {
            $this->errorMsg = "this is not a file";
            return false;
        }
        if (unlink($file)) {
            return true;
        } else {
            $this->errorMsg = "fail to remove the file!";
            return false;
        }
    }
1165985
public static function removeFile(string $file)
    {
        // Copied from [[removeDirectory()]]
        try {
            unlink($file);
        } catch (ErrorException $e) {
            if (DIRECTORY_SEPARATOR === '\\') {
                // last resort measure for Windows
                $lines = [];
                exec("DEL /F/Q \"$file\"", $lines, $deleteError);
            } else {
                throw $e;
            }
        }
    }
804641
public function remove(CacheableInterface $item)
    {
        $targetFile = $this->getTargetFile($item->getHashKey());
        if (file_exists($targetFile) && !unlink($targetFile)) {
            throw new \RuntimeException(
                sprintf('Unable to delete %s cache file', $targetFile)
            );
        }
    }
821867
public function removeLoaderByFile($file)
    {
        foreach ($this->loaders as $i => $loader) {
            /** @var LoaderInterface $loader */
            if ($loader->supports($file)) {
                unset($this->loaders[$i]);
            }
        }
    }
136124
private function doesFileChecksFailed(string $file): bool
    {
        //check if file exist
        if (!\file_exists($file)) {
            return true;
        }

        //take cache from file
        $cacheValue = include $file;

        //check if cache is expired and delete file from storage
        if ($cacheValue['expires'] <= \time() && $cacheValue['expires'] !== 0) {
            \unlink($file);

            return true;
        }

        return false;
    }
721892
public static function delete($files)
    {
        $files = (array) $files;

        foreach ($files as $file) {
            $file = Path::clean($file);

            // Try making the file writable first. If it's read-only, it can't be deleted
            // on Windows, even if the parent folder is writable
            @chmod($file, 0777);

            // In case of restricted permissions we zap it one way or the other
            // as long as the owner is either the webserver or the ftp
            // TODO: Remove exception and use PHP7 throwable
            if (@!unlink($file)) {
                throw new FilesystemException(__METHOD__ . ': Failed deleting ' . basename($file));
            }
        }

        return true;
    }
944310
public function remove(TempFile $file)
    {
        // TODO: cleanup file?

        if ($this->session->has('mediamanager.temp_files') && isset($this->session->get('mediamanager.temp_files')[$file->getId()])) {
            $tempFiles = $this->session->get('mediamanager.temp_files');
            unset($tempFiles[$file->getId()]);
            $this->session->set('mediamanager.temp_files', $tempFiles);
        }

        return $this;
    }
604021
public function delete($file)
    {
        return ($this->isConnected() === true) ? ftp_delete($this->getConnection(), $file) : false;
    }
962884
protected function unlink($file)
    {
        ErrorHandler::start();
        $res = unlink($file);
        $err = ErrorHandler::stop();

        // only throw exception if file still exists after deleting
        if (!$res && file_exists($file)) {
            throw new Exception\RuntimeException(
                "Error unlinking file '{$file}'; file still exists", 0, $err
            );
        }
    }
1106004
public function delete( $file ) {
		$key = array_search( $file, $this->assets[ $this->type ] );
		unset( $this->assets[ $this->type ][ $key ] );
		unset( $this->attr[ $this->type ][ $key ] );
	}
464193
public function attach($file = __FILE__)
    {
        if (!file_exists($file)) {
            $touch = touch($file);
            if (!$touch) {
                throw new \RuntimeException("file is not exists and it can not be created. file: {$file}");
            }
        }
        $key = ftok($file, 'a');
        $this->shm = shm_attach($key, $this->size); //allocate shared memory
    }
1370628
public function remove($files)
    {
        if ($files instanceof \Traversable) {
            $files = iterator_to_array($files, false);
        } elseif (!is_array($files)) {
            $files = array($files);
        }
        $files = array_reverse($files);
        foreach ($files as $file) {
            if (is_link($file)) {
                // See https://bugs.php.net/52176
                if (!@(unlink($file) || '\\' !== DIRECTORY_SEPARATOR || rmdir($file)) && file_exists($file)) {
                    $error = error_get_last();
                    throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, $error['message']));
                }
            } elseif (is_dir($file)) {
                $this->remove(new \FilesystemIterator($file, \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS));

                if (!@rmdir($file) && file_exists($file)) {
                    $error = error_get_last();
                    throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, $error['message']));
                }
            } elseif (!@unlink($file) && file_exists($file)) {
                $error = error_get_last();
                throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
            }
        }
    }