PHP unlink Function Delete a file program code _php Tutorial

Source: Internet
Author: User
In PHP we want to delete a specified file we can use the unlink function to implement, below I give you detailed description of the unlink function to delete a specified file of the specific method, there is a need to know the friend can refer to.

The unlink () function deletes the file.

If successful, returns True, which returns false if it fails.

The code is as follows Copy Code

Unlink ("test.txt");
?>

Cases

The code is as follows Copy Code

$file = "Test.txt", if (!unlink ($file)) {
Echo ("Error deleting $file"); }else {
Echo ("Deleted $file"); }
?>

Plus judgment.

The code is as follows Copy Code

$file = "Test.txt";
if (unlink ($file))
{
echo "File $file deleted successfully! ";
}
Else
{
echo "File $file Delete failed! ";
}
?>


Output Result:

File Test.txt deleted successfully!


The following is added to determine whether the file exists:

The code is as follows Copy Code

$myfile = "./test1.txt";
if (file_exists ($myfile)) {
$result =unlink ($myfile);
echo $result;
}
?>

The rmdir () function deletes a directory, returns TRUE successfully, or returns FALSE.

Grammar:

BOOL RmDir (String dirname)

Example:

The code is as follows Copy Code

$dirname = ' TestDir ';
if (RmDir ($dirname)) {
echo "Directory $dirname deleted successfully";
} else {
echo "Directory $dirname delete failed";
}
?>

http://www.bkjia.com/PHPjc/628815.html www.bkjia.com true http://www.bkjia.com/PHPjc/628815.html techarticle in PHP we want to delete a specified file we can use the unlink function to implement, below I give you detailed description of the unlink function to delete a specified file of the specific method, there is a need ...

  • Related Article

    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.