Home  >  Article  >  Backend Development  >  Can php delete files?

Can php delete files?

藏色散人
藏色散人Original
2022-01-06 09:55:162477browse

php can delete files. The method of deleting files: 1. Create a PHP sample file; 2. Find the file to be deleted; 3. Delete the file through the "unlink(filename,context)" syntax. .

Can php delete files?

#The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

Can php delete files?

php can delete files.

php can use the unlink function to delete files

The specific usage is as follows

unlink($filename);

unlink() Function introduction:

unlink() Function deletes files.

If successful, this function returns TRUE. On failure, returns FALSE.

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

Example

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

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Can php delete files?. 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