如何删除目录 如何实现在父目录下面删除所有不包含php文件的目录?以及里面非php的文件 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function deleteHandle($dir){ if(file_exists($dir)){ //判断路径是否存在 if(is_dir($dir)){ //判断是否是目录 $opendir = opendir($dir); //对目录进行操作 if($opendir){ while(($file = readdir($opendir)) !== false){ $path = $dir.$file; $fileType = filetype($path); if($fileType == 'dir'){ deleteHandle($path); } else if($fileType == 'file'){ $fileSuffix = explode('.',basename($path)); if($fileSuffix['1'] != 'php'){ unlink($path); } } else{ unlink($path); } } unlink($path); } else{ echo "打开文件失败!"; } } }}可以对此函数进行适当修改。 function deleteHandle($dir){ if(file_exists($dir) && is_readable($dir)){ if(is_dir($dir)){ $opendir = opendir($dir); if($opendir){ while(($file = readdir($opendir)) !== false){ if($file == "." || $file == ".."){ continue; } $path = $dir.$file; $fileType = filetype($path); if($fileType == 'dir'){ deleteHandle($path.'/'); } else if($fileType == 'file'){ $fileSuffix = explode('.',basename($path)); if($fileSuffix['1'] != 'php'){ unlink($path); } } else{ unlink($path); } } } else{ echo "打开文件失败!"; } closedir($opendir); } else{ echo 'false2'; } } else{ echo 'false1'; }} 菜鸟请教大家如何打开整个项目??????????????? 急聘PHP高级程序员 工作地址:成都 新浪微博api问题 各位大侠帮忙 能告诉我蘑菇街添加商品是怎么做的吗? 关于curl的一个让我很纠结的问题,求解答 网站后台问题 php能不能将远程的图片地址模拟成本地的 ORACLE字符集编码问题 thinkphp框架下的多表事务操作 thinkphp的源代码 php fckeditor 2.5 赋值问题 怎么移动discuz7.0页头“注册 登录”的位置??
if(file_exists($dir)){ //判断路径是否存在
if(is_dir($dir)){ //判断是否是目录
$opendir = opendir($dir); //对目录进行操作 if($opendir){
while(($file = readdir($opendir)) !== false){ $path = $dir.$file; $fileType = filetype($path);
if($fileType == 'dir'){
deleteHandle($path);
}
else if($fileType == 'file'){
$fileSuffix = explode('.',basename($path)); if($fileSuffix['1'] != 'php'){
unlink($path);
}
}
else{
unlink($path);
}
} unlink($path);
}
else{
echo "打开文件失败!";
}
}
}
}可以对此函数进行适当修改。
if(file_exists($dir) && is_readable($dir)){
if(is_dir($dir)){
$opendir = opendir($dir); if($opendir){
while(($file = readdir($opendir)) !== false){ if($file == "." || $file == ".."){
continue;
} $path = $dir.$file; $fileType = filetype($path);
if($fileType == 'dir'){
deleteHandle($path.'/');
}
else if($fileType == 'file'){
$fileSuffix = explode('.',basename($path)); if($fileSuffix['1'] != 'php'){
unlink($path);
}
}
else{
unlink($path);
}
}
}
else{
echo "打开文件失败!";
}
closedir($opendir);
}
else{
echo 'false2'; }
}
else{
echo 'false1';
}}