Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

unlink

Description

Deletes a file

Syntax

unlink(
    string $filename,
    ?resource $context = null
): bool

Parameters

filename

Path to the file.

If the file is a symlink, the symlink will be deleted. On Windows, to delete a symlink to a directory, rmdir() has to be used instead.

context

A context stream resource.

Return

Returns true on success or false on failure.

Examples

1 · filename

<?

$filename = 'unlink.txt';
$mode = 'a';

$stream = fopen($filename, $mode);

    $data = 'data';

    fwrite($stream, $data);

fclose($stream);

$return = unlink($filename);

var_export($return);

?>
true

2 · context

<?

$filename = 'unlink.txt';
$mode = 'a';

$stream = fopen($filename, $mode);

    $data = 'data';

    fwrite($stream, $data);

fclose($stream);

$context = stream_context_create();

$return = unlink($filename, $context);

var_export($return);

?>
true
HomeMenu