The phpunlink function deletes a file program code. In php, we can use the unlink function to delete a specified file. The following describes how to delete a specified file by the unlink function, if you need to delete a specified file in php, you can use the unlink function to implement it. next I will introduce in detail how the unlink function deletes a specified file, for more information, see.
The unlink () function deletes a file.
If the call succeeds, true is returned. if the call fails, false is returned.
| The code is as follows: |
|
|
Unlink ("test.txt ");
?> |
Example
| The code is as follows: |
|
|
$ File = "test.txt"; if (! Unlink ($ file )){
Echo ("Error deleting $ file");} else {
Echo ("Deleted $ file ");}
?> |
Add judgment
| The code is as follows: |
|
|
$ File = "test.txt ";
If (unlink ($ file ))
{
Echo "file $ file deleted successfully! ";
}
Else
{
Echo "file $ file deletion failed! ";
}
?>
|
Output result:
The file test.txt is deleted successfully!
The following code checks whether a file exists:
| The code is as follows: |
|
|
$ Myfile = "./test1.txt ";
If (file_exists ($ myfile )){
$ Result = unlink ($ myfile );
Echo $ result;
}
?> |
The rmdir () function deletes a directory and returns TRUE if the directory is successfully deleted. otherwise, FALSE is returned.
Syntax:
Bool rmdir (string dirname)
Example:
| The code is as follows: |
|
|
$ Dirname = 'testdir ';
If (rmdir ($ dirname )){
Echo "directory $ dirname deleted successfully ";
} Else {
Echo "directory $ dirname deletion failed ";
}
?> |
...