Finding file size

tsalexey544's Avatar, Join Date: Nov 2006
Go4Expert Member
I'm altering a script I found that itterates through a directory and list the files and the file sizes. I changed the script to seach a seperate directory "data". The directory is stored in my currect directory.

The script works fine until I have it search the directory data, it returns the file names, but it doesnt return the filesize. Any hints?

Here is what I have already.

PHP Code:
$theDirectory            "data";
$listDirectories    false;

if(
is_dir($theDirectory))
{
    echo 
"<table><tr><td>Name</td><td>Type</td><td>Size</td></tr>";
    
$dir opendir($theDirectory);
    while(
false !== ($file readdir($dir)))
    {
        
$type    filetype($theDirectory ."/"$file);
        if(
$listDirectories || $type != "dir")
        {
            echo 
"<tr><td>" $file "</td>";
            echo 
"<td>" $type "</td>";
            echo 
"<td>";
            if(
$type == "file")
                echo 
filesize($file);
            echo 
"</td></tr>";
        }
    }
    
closedir($dir);
    echo 
"</table>";
}
else
{
    echo 
$theDirectory " is not a directory";

When I have the directory set to "." everything works fine, but it's only when I set it to data that I get the trouble.

Thanks
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
You have to specify the full path to the directory!
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
http://www.go4expert.com/showthread.php?t=290 checkout this thread, you may find some help in this code.