Home  >  Article  >  Backend Development  >  PHP删除文件夹内及其文件

PHP删除文件夹内及其文件

WBOY
WBOYOriginal
2016-06-20 13:03:341069browse

<p>function Delete($path){</p><p>    if (is_dir($path) === true)</p><p>    {</p><p>        $files = array_diff(scandir($path), array('.', '..'));</p><p>        foreach ($files as $file)</p><p>        {</p><p>            Delete(realpath($path) . '/' . $file);</p><p>        }</p><p>        return rmdir($path);</p><p>    }</p><p>    else if (is_file($path) === true)</p><p>    {</p><p>        return unlink($path);</p><p>    }</p><p>    return false;</p><p>}</p>

语法:

<p><?php</p><p>$path = "images/";</p><p>Delete($path); // This will delete images folder along with its contents.</p><p>?></p>


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