Want to delete a file from the system using PHP? Use the following PHP code to delete a file from the system. We have used unlike()
function to delete a file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php /** * PHP program to delete a file named test.txt */ $file_pointer = "test.txt"; if (!unlink($file_pointer)) { echo ("$file_pointer cannot be deleted due to an error"); } else { echo ("$file_pointer has been deleted."); } ?> |
Program Output
1 | test.txt has been deleted. |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.