PHP traverses file directories and clears files in directories

巴扎黑
Release: 2016-11-24 13:53:20
Original
1158 people have browsed it

Today I was bored and practiced the PHP program for traversing file directories, and wrote the following two programs, but the quality is not very good, pat~~~

1. Clear PHP cache files

<?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);
}
}
?>
Copy after login


Related labels:
php
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