From the course: PHP Techniques: Working with Files and Directories
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Deleting files - PHP Tutorial
From the course: PHP Techniques: Working with Files and Directories
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
-
-
-
(Locked)
Filesystem basics6m 6s
-
Relative paths and magic constants4m 53s
-
(Locked)
Accessing files5m 4s
-
(Locked)
Reading from files4m 52s
-
(Locked)
Reading line by line5m 9s
-
(Locked)
File permissions5m 34s
-
(Locked)
Writing to files5m 5s
-
(Locked)
Writing line returns2m 28s
-
(Locked)
Deleting files2m 38s
-
(Locked)
Moving the file pointer7m 36s
-
(Locked)
Examining file details6m 52s
-
(Locked)
Challenge: Create a log file2m 2s
-
(Locked)
Solution: Create a log file3m 17s
-
(Locked)
-
-
-