php檔案遍曆類:FileBianli.class.php

來源:互聯網
上載者:User

標籤:style   blog   io   color   os   sp   檔案   div   on   

 1 <?php 2  3     class FileBianli{ 4         private $dirname;   5         private $dirsize=0; 6         private $totalsize=0;//目前的目錄大小 7          8          9         function bianliDir($dirname){10 11             $dir=opendir($dirname);12 13             while($fileName=readdir($dir)){14                 if($fileName!="." && $fileName!=".."){15                     $file=$dirname.‘/‘.$fileName;16                     if(is_dir($file)){17                         echo "<font color=‘red‘>".$fileName."-".date("Y-m-d H:i:s")."-".filetype($file)."-".$this->toSize($this->dirsize($file))."-</font><br>";18                         $totalsize+=$this->dirsize($file);19                     }else{20                         echo "<font color=‘blue‘>".$fileName."-".date("Y-m-d H:i:s")."-".filetype($file)."-".$this->toSize(filesize($file))."-</font><br>";21                         $totalsize+=filesize($file);22                     }23                 }24             }25             closedir($dir);26             echo $dirname."共計大小為:".$this->toSize($totalsize)."<br>";27             return true;28         }29 30         31         //將位元組轉換成GB,MB,KB,BYTE32         function toSize($size){33             $dw="Bytes";34             if($size > pow(2,30)){35                 $size=round($size/pow(2,30),2);36                 $dw="GB";37             }else if($size > pow(2,20)){38                 $size=round($size/pow(2,20),2);39                 $dw="MB";40             }else if($size > pow(2,10)){41                 $size=round($size/pow(2,10),2);42                 $dw="KB";43             }else{44                 $dw="bytes";45             }46             return $size.$dw;47             48         }49         
      //計算目錄的大小50 function dirsize($dirname){51 52 $dir=opendir($dirname);53 54 while($filename=readdir($dir)){55 $file=$dirname."/".$filename;56 if($filename!="." && $filename!=".."){57 if(is_dir($file)){58 $this->dirsize($file);//遞迴完成59 }else{60 $dirsize+=filesize($file);61 }62 }63 }64 65 closedir($dir);66 return $dirsize;67 }68 }69 ?>

 

php檔案遍曆類:FileBianli.class.php

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.