Is there any downside to using unlink()
to delete a folder (and its contents) in php?
Asked
Active
Viewed 66 times
-1

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129

Benjamin Allison
- 2,134
- 3
- 30
- 55
-
possible duplicate of [How do I recursively delete a directory and its entire contents (files+sub dirs) in PHP?](http://stackoverflow.com/questions/3338123/how-do-i-recursively-delete-a-directory-and-its-entire-contents-filessub-dirs) – Patrick B. Mar 14 '13 at 21:43
1 Answers
4
You can't. unlink
can only delete files, not directories. You can delete directories with rmdir
, but that will only delete empty directories. You will have to unlink individual files first.

Explosion Pills
- 188,624
- 52
- 326
- 405
-
**Bonus:** if you look in the examples for `rmdir`, someone posted a function that'll recursively delete a directory tree. – Mr. Llama Mar 14 '13 at 19:23