note 34092 deleted from ref.filesystem by felipe
| From: | felipe@php.net | Date: | Mon, 10 Dec 2007 17:55:59 +0000 |
| Subject: | note 34092 deleted from ref.filesystem by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133224@lists.php.net to get a copy of this message | ||
Note Submitter: aggarwal_deep at hotmail dot com
----
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);
?>