-
Notifications
You must be signed in to change notification settings - Fork 0
removeFile
Corey Avis edited this page Sep 23, 2026
·
3 revisions
Removed a specified file from the filesystem. This method includes built-in security checks to prevent Directory Traversal attacks by ensuring the target file resides strictly within the designated trusted root directory.
📌 This method safely mitigates
../path traversal exploits by utilizingrealpath(). However, ensure that$this->pathis properly sanitized and initialized before invoking this method.
removeFile(string $filename): bool
filename (string) : The name or path of the file to be removed. Can be an absolute path or relative to the configured base path.
(bool)
: Returns true on success and false on failure.
$file->removeFile('file.txt');
- Throws an exception if file does not exists or access is restricted.
- Throws an exception if target is a directory, not a file.
- Throws an exception if permission is denied.