unlink() function in PHP


The unlink() function deletes a file. It returns TRUE on success, or FALSE on failure. It returns TRUE on success and FALSE on failure.

Syntax

unlink(file_path, context)

Parameters

  • file_path − Set the name of the file to be deleted.

  • context − Set the behavior of the stream.

Return

The unlink() function returns TRUE on success and FALSE on failure.

Example

 Live Demo

<?php
$file_pointer = "one.txt";
if (!unlink($file_pointer)) {
   echo ("File can’t be deleted!");
} else {
   echo ("File deleted!");
}
?>

Output

File can’t be deleted!

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 24-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements