Home > Backend Development > PHP Problem > How to delete a single file in php

How to delete a single file in php

王林
Release: 2023-03-04 11:26:01
Original
2826 people have browsed it

How to delete a single file in php: You can use the unlink() function to delete the file. Returns true if file deletion is successful. If deletion of the file fails, false is returned. The specific usage method is: [unlink($filename)].

How to delete a single file in php

The unlink() function deletes files. If successful, the function returns TRUE. On failure, returns FALSE.

(Recommended tutorial: php graphic tutorial)

Syntax:

unlink(filename,context)
Copy after login

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 can modify the behavior of the stream.

(Learning video recommendation: php video tutorial)

Code implementation:

<?php
$file = "test.txt";
if (!unlink($file))
{
echo ("Error deleting $file");
}
else
{
echo ("Deleted $file");
}
?>
Copy after login

The above is the detailed content of How to delete a single file 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