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

PHP删除文件夹内及其文件

WBOY
Release: 2016-06-20 13:03:34
Original
1125 people have browsed it

<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>
Copy after login

语法:

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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template