note 34092 added to ref.filesystem

From: Date: Wed, 16 Jul 2003 07:43:50 +0000
Subject: note 34092 added to ref.filesystem
Groups: php.notes 
Request: Send a blank email to php-notes+get-52168@lists.php.net to get a copy of this message
The following souce is the combination of 3 different function ,does the listing of the whole files in directories or sub-directories of a base directory(given). And find out the maximum file size of given application files. for example it will tell the maximum file size of ppt file that is placed in the directory. <? function showExtension($file){ if(is_file($file)){ $fileInfo = pathinfo($file); $extension=$fileInfo["extension"]; } else { $extension=""; } return $extension; } function fsize($size) { $a = array("B", "KB", "MB", "GB", "TB", "PB"); $pos = 0; while ($size >= 1024) { $size /= 1024; $pos++; } return round($size,2)." ".$a[$pos]; } function ls ($curpath) { $dir = dir($curpath); $file_namearr = array("ETC","PPT","XLS","DOC","PDF"); echo("<b>$curpath</b>"); echo "<blockquote>"; $file_sizearr = array(1,1,1,1,1); while ($file = $dir->read()) { if($file != "." && $file != "..") { if (is_dir($curpath.$file)) { ls($curpath.$file."/"); } else { $filext= strtoupper(showExtension($curpath.$file)); $curr_key = 0; $curr_key = array_search($filext,$file_namearr); if($curr_key){ //echo "<br>$filext:$curr_key"; $curr_file_size = $file_sizearr[$curr_key]; if(filesize($curpath.$file)>$curr_file_size){ $file_sizearr[$curr_key]= intval(filesize($curpath.$file)); } } //echo"<br> $file : ".fsize($curpath.$file); } } }//while ends for($k=0;$k<5;$k++){ echo"<br>".$file_namearr[$k].":".fsize($file_sizearr[$k]); } $dir->close(); echo "</blockquote>"; return; } $startpath = "/home6/docmng/"; ls($startpath); ?> ---- Manual Page -- http://www.php.net/manual/en/ref.filesystem.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34092 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34092&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34092&report=yes

« previous php.notes (#52168) next »