...

View Full Version : include filesizes in PHP directory list



brothercake
01-24-2003, 11:46 AM
My apologies if this has been asked before - I couldn't find it in search ..

I have a listing script like this:



<?



//define the path as relative to here
$path = ".";

//open directory for list
$dir_handle = opendir($path) or die("Unable to open $path");




//print filenames function
function printFileNames($ext) {
global $docList,$dir_handle;
while ($file = readdir($dir_handle)) {
if(ereg("\.".$ext,$file)) {
$docList .= "\t<li><a href=\"$file\" target=\"_blank\">$file</a></li>\n";
}
}
}





//list of word documents
$docList = "<p>The following documents are available in MS Word format:";
$docList .= "<ul>\n";
printFileNames("doc");
$docList .= "</ul>\n";

//echo list
echo ($docList);




//close directory
closedir($dir_handle);

?>



Is there a way I can include in the output the size of each file, without opening them all

mordred
01-24-2003, 12:21 PM
Maybe I'm misunderstanding you, but couldn't you just make use of the filesize() function?
http://www.php.net/manual/en/function.filesize.php

brothercake
01-24-2003, 05:18 PM
That's ideal, thank you (note to self - check documentation before asking questions :rolleyes: )



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum