From the course: PHP Techniques: Working with Files and Directories

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Deleting files

Deleting files - PHP Tutorial

From the course: PHP Techniques: Working with Files and Directories

Start my 1-month free trial

Deleting files

- [Instructor] Now that we know how to create files, let's learn how to delete them. Deleting files is easy as long as you keep three things in mind. The first is that you cannot delete an open file. The second is that you need write permission on the directory containing the file in order to delete it. And the third thing to keep in mind is that the name of the PHP function for deleting a file is a little bit unusual. It is unlink, it's not F delete or file delete or something else you might guess. It can be a little bit hard to remember. If you send a file path to unlink, it will try to delete the file and return true or false. I'll create a new file in the PHP sandbox and I'll call it file_delete.php and I'll add some PHP tags and then inside, a file path. filepath=__DIR__./delete_me.txt. I'll go ahead and also use the file put contents that we just learned. file_put_contents with the file path and let's put some…

Contents