Home  >  Article  >  Backend Development  >  How to delete a directory or file in php?

How to delete a directory or file in php?

青灯夜游
青灯夜游Original
2020-11-03 16:38:242844browse

In PHP, you can use the unlink() function to delete files, the syntax is "unlink (specified file)", if it succeeds, it returns true, if it fails, it returns false; you can use the rmdir() function to delete an empty directory, the syntax is " rmdir (specified directory)", returns TRUE if successful, and FALSE if failed.

How to delete a directory or file in php?

Recommended: "PHP Video Tutorial"

Sometimes we need to use PHP to delete files and folders ( Directory), PHP originally has functions that can be implemented. Let’s simply record the code below so that it can be easily copied later. Let’s take a look at the code first

unlink() function is used to delete files. Returns true if successful, false if failed. The rmdir() function is used to delete empty directories. It attempts to delete the directory specified by dir. The directory must be empty and must have appropriate permissions.

An example: delete all ".svn" folders under a certain folder (including their contents must also be deleted).

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of How to delete a directory or file in php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn