How to delete a file in PHP? Unlink php - deleting files How it all works.
We continue the lesson, which is dedicated to the topic “ Working with PHP Files" If you haven’t read the previous one, I recommend reading it, and for those who have read it, let’s move on. In this lesson you will learn how to delete a created or existing file using PHP, copy or rename, lock a file.
Well, if you are ready, then go to battle...
Deleting a file in PHP
If you need to delete any file, use the PHP unlink() function:
Unlink(filename);
Filename – here enter the name of the file you want to delete.
Let's say we need to delete the file “file.txt”, an example to fill would be like this:
Unlink("file.txt");
Ready code: