Home  >  Article  >  Backend Development  >  How to use php unlink function

How to use php unlink function

藏色散人
藏色散人Original
2019-02-20 16:31:003626browse

The unlink() function is a built-in function in PHP, used to delete files. The syntax is [unlink(filename,context)]. It takes the file name of the file that must be deleted as a parameter. It returns True when successful and returns when failed. False.

How to use php unlink function

How to use the php unlink() function?

Function: Delete files.

Syntax:

unlink(filename,context)

Parameters:

filename: Required. Specifies the files to be deleted.

context: optional. Specifies the environment for a file handle. Context is a set of options that modify the behavior of the stream.

Return value: If successful, return true, if failed, return false.

php unlink() function example

<?php
$file = "./test.txt";
if (!unlink($file))
{
    echo ($file."删除失败");
}
else
{
    echo ($file."删除成功");
}
?>

This article is an introduction to the PHP unlink function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use php unlink function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn