您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP遍历文件目录与清除目录中的文件

2025/11/26 12:38:53发布21次查看
今天无聊中练习了一下php遍历文件目录的程序,编写了以下两个程序,不过质量不是很好,轻拍~~~
1、清除php缓存文件
<?php function read_dir($dir,$file) { $a =strpos($file,".php"); if($a>0) { unlink($dir . $file); echo "delete $dir$file <br>"; return true; } if(strpos($file,".") === 0 || strpos($file,".") !== false ) return true; if(strpos($file,".") === false || strpos($dir,"/") === false) { $dir = $dir . $file . "/"; if(!is_dir($dir)) return false; $dh = opendir($dir); while(($file = readdir($dh)) != false) { read_dir($dir,$file); //递归调用 } } } function clear_caches() { $dir = "./temp/"; //要清除的php缓存文件目录 if(!is_dir($dir)) die("it is not a dir"); $dh = opendir($dir); while(($file = readdir($dh) )!=false) { //var_dump($file); read_dir($dir,$file); } } ?>
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product