该函数执行成功,但没有删除任何文件夹。
public function ulink(){
$path='/home/doman/public_html/projectname/';
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; }
}
最佳答案
尝试使用此代码来删除所有文件夹和子文件夹。
function viewDir($path) {
return is_file($path) ?
@unlink($path) :
array_map(__FUNCTION__, glob($path.'/*')) == @rmdir($path);
}
$dir=$_SERVER["DOCUMENT_ROOT"]."/xxxx/xxxx";
echo $dir;
viewDir($dir);
您可以使用此函数并根据需要更改$dir
值。
它对我来说工作得很好..
关于php - 如何删除服务器(cpanel)中所有带有文件的文件夹?我的错误在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26114977/