Oihana PHP

deleteFile.php

Table of Contents

Functions

deleteFile()  : bool
Deletes a file from the filesystem.

Functions

deleteFile()

Deletes a file from the filesystem.

deleteFile(string $filePath[, bool $assertable = true ][, bool $isReadable = true ][, bool $isWritable = true ]) : bool

This function optionally asserts that the file exists and meets the specified readability and writability requirements before attempting deletion. If the deletion fails, a FileException is thrown.

Parameters
$filePath : string

The path to the file to delete.

$assertable : bool = true

Whether to perform assertions on the file before deletion (default: true).

$isReadable : bool = true

Whether to assert that the file is readable (default: true).

$isWritable : bool = true

Whether to assert that the file is writable (default: true).

Tags
throws
FileException

If the file does not meet the assertions or cannot be deleted.

example
$file = 'example.txt';
file_put_contents($file, 'Sample content');

try
{
    deleteFile($file);
    echo "File deleted successfully.";
}
catch (FileException $e)
{
    echo "Error deleting file: " . $e->getMessage();
}
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
bool

Returns true on successful deletion.


        
On this page

Search results