Phpunlink function to delete a file program code _ PHP Tutorial

Source: Internet
Author: User
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 ";
}
?>

...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.