search
HomeBackend DevelopmentPHP ProblemWhat is the code to delete files in php

What is the code to delete files in php

May 05, 2022 pm 07:46 PM
phpphp file directory

php code to delete files is "unlink($file,$cont)". The unlink() function is used to delete the specified file. It accepts a non-omit parameter "$file", which specifies the file path to be deleted, and an omitted parameter "$cont", which specifies the file handle environment and can modify the behavior of the stream. A set of options.

What is the code to delete files in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In PHP, if you want to delete files, you can Use the unlink() function.

The unlink() function can delete the specified file. It returns TRUE when the function is executed successfully and FALSE when it fails.

The code to delete the file is as follows:

unlink($file,$cont)
Parameter Description
$file Required. Specifies the path of the file to be deleted.
$cont Optional. Specifies the environment for a file handle. cont is a set of options that can modify the behavior of the stream.

Example: Delete the specified file newtest.txt

What is the code to delete files in php

<?php 
header("content-type:text/html;charset=utf-8");
$file = &#39;newtest.txt&#39;;
if(file_exists($file)){
    if(unlink($file)){
        echo $file.&#39; 删除成功!&#39;;
    }else{
        echo $file.&#39; 删除失败!&#39;;
    }
}else{
    echo $file.&#39; 不存在!&#39;;
}
?>

What is the code to delete files in php

at Refresh it and it will display:

What is the code to delete files in php

Because the file has been deleted, it no longer exists.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the code to delete files in php. 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools