11 08 2015

31. 删除文件夹内容

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function Delete($path)
{
    if (is_dir($path) === true)
    {
        $files = array_diff(scandir($path), array('.', '..'));
        foreach ($files as $file)
        {
            Delete(realpath($path) . '/' . $file);
        }
        return rmdir($path);
    }
    else if (is_file($path) === true)
    {
        return unlink($path);
    }
    return false;
}

语法:

?
1
2
3
4
<?php
$path = "images/";
Delete($path); // This will delete images folder along with its contents.
?>
发表评论