Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   Finding file size (http://www.go4expert.com/forums/finding-file-size-t3029/)

tsalexey544 15Feb2007 23:14

Finding file size
 
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

pradeep 16Feb2007 10:08

Re: Finding file size
 
You have to specify the full path to the directory!

pradeep 16Feb2007 10:13

Re: Finding file size
 
http://www.go4expert.com/showthread.php?t=290 checkout this thread, you may find some help in this code.


All times are GMT +5.5. The time now is 08:27.