📄 logfiles.php
字号:
<?php
/*
遍历所有目录和目录下边的文件,并返回文件的相对位置
power by:antsnet.net
email:antsnet@163.com or antsnet.net@163.com
<code>
$d=new document();
$f=$d->fetch("..");
$s=$d->search("./myclass","cls");#search file form appoint folder
$d->mult_create_folder("an/ant/ants/ants.html");#create multilevel folder
print_r( $f["folder"]);//返回所有文件夹的数组
print_r($f["file"]);//返回所有文件的数组
</code>
*/
header("Content-type:text/html;charset=gb2312");
$d=new document();
$fArray=$d->one_directory("log");
$files=$fArray["file"];
echo "分析:";
foreach ($files as $file){
$basefile=basename($file);
echo "<a href=\"?{$basefile}\" onclick=\"analyze('{$basefile}');\">{$basefile}</a> ";
}
/*$f=$d->fetch("..");
$s=$d->search(".","cls");
print_r($s);
*/
/*directory control class*/
class document{
private $file_array=array();
private $folder_array=array();
private $all_array=array();
/*fetch all file and folder*/
function fetch($dir){
if(is_dir($dir)){
$H=opendir($dir);
while(false!==($_file=readdir($H))){
if(is_dir($dir."/".$_file)&&$_file!="." && $_file!=".." && $_file!=="Thumbs.db"){
array_push($this->folder_array,$dir."/".$_file);
$this->fetch($dir."/".$_file);
}elseif(is_file($dir."/".$_file)&&$_file!="." && $_file!=".." && $_file!=="Thumbs.db"){
array_push($this->file_array,$dir."/".$_file);
}
}
$this->all_array["folder"]=$this->folder_array;
$this->all_array["file"]=$this->file_array;
return $this->all_array;
closedir($H);
}elseif(is_file($dir)){
$this->all_array["file"]=$dir;
return $this->all_array;
}else{
return $this->error("this folder or file does not exits,please check it out.");
}
}
/*fetch the contents of file*/
function fetch_contents($file){
if(!@function_exists(file_get_contents)){
$fp = @fopen($file, 'r');
if(!$fp){
die ("Unable to open this $file");
}else{
$contents = fread($fp, filesize($file));
fclose($fp);
return $contents;
}
}else{
return @file_get_contents($file);
}
}
/*put contents to file*/
function put_contents($file,$file_contents){
if(!@function_exists(file_put_contents)){
if($fp = @fopen($file, 'w')) {
flock($fp,LOCK_EX);
fwrite($fp, $file_contents);
fclose($fp);
}
else {
die('Unable to write cache.');
}
}else{
file_put_contents($file,$file_contents);
}
}
/*only show folder level 1*/
function one_directory($directory){
if(is_dir($directory)){
$H=opendir($directory);
while(false!==($_file=readdir($H))){
if(is_dir($directory."/".$_file)&&$_file!="." && $_file!=".." && $_file!=="Thumbs.db"){
array_push($this->folder_array,$directory."/".$_file);
}elseif(is_file($directory."/".$_file)&&$_file!="." && $_file!=".." && $_file!=="Thumbs.db"){
array_push($this->file_array,$directory."/".$_file);
}
}
}
$this->all_array["folder"]=$this->folder_array;
$this->all_array["file"]=$this->file_array;
return $this->all_array;
closedir($H);
}
/*create folder*/
function create_folder($folder_name){
if(!is_dir($folder_name)){
return @mkdir($folder_name);
}else{
return false;
}
}
/*create multilevel directory*/
function mult_create_folder($path) {
echo $path,'<BR>' ; #create directory process
$path = str_replace('\\\\','/',$path) ;
if ( is_dir($path) ) return false ;
if ( file_exists($path) ) return false ;
/*fetch parent's directory name*/
$parent = substr($path ,0, strrpos($path,'/') ) ;
if ( $parent==='' || $parent==='.' || $this->mult_create_folder( $parent ) )
return @mkdir($path) ;
else return false ;
}
/*delete folder ,notice:this folder is empty*/
function delete_folder($folder_name){
if(is_dir($folder_name)){
return @rmdir($folder_name);
}else{
return false;
}
}
/*delete all files or folders in this folder*/
function mult_delete_folder($dirName){
if(! is_dir($dirName))
{
return false;
}
$handle = @opendir($dirName);
while(($file = readdir($handle)) !== false)
{
if($file != '.' && $file != '..')
{
$dir = $dirName . DIRECTORY_SEPARATOR . $file;
is_dir($dir) ? $this->mult_delete($dir) : unlink($dir);
}
}
closedir($handle);
$result = rmdir($dirName) ? true : false;
return $result;
}
/*delete file*/
function delete_file($file_name){
if(is_file($file_name)){
return @unlink($file_name);
}else{
return false;
}
}
/*search, search appoint file or folder under this path , return relatively path*/
function search($path,$file){
if(is_dir($path)){
$H=opendir($path);
while(false!==($_file=readdir($H))){
if(is_dir($path."/".$_file)&&$_file!="." && $_file!=".." && $_file!=="Thumbs.db"){
if(eregi($file,$path."/".$_file)){
array_push($this->folder_array,$path."/".$_file);
}
$this->search($path."/".$_file,$file);
}elseif(is_file($path."/".$_file)&&$_file!="." && $_file!=".." && $_file!=="Thumbs.db"){
if(eregi($file,$_file)){
array_push($this->file_array,$path."/".$_file);
}
}
}
$this->all_array["folder"]=$this->folder_array;
$this->all_array["file"]=$this->file_array;
return $this->all_array;
closedir($H);
}elseif(is_file($path)){
if(eregi($file,$path)){
$this->all_array["file"]=$path;
}
return $this->all_array;
}else{
return $this->error("this folder or file does not exits,please check it out.");
}
}
/*error*/
function error($message){
return $message;
}
/*end of class*/
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -