What is the code to delete files in php

青灯夜游
Release: 2023-03-15 22:06:01
Original
3201 people have browsed it

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)
Copy after login
ParameterDescription
$file Required. Specifies the path of the file to be deleted.
$contOptional. 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;;
}
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template