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 ...