1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Finding file size

Discussion in 'PHP' started by tsalexey544, Feb 15, 2007.

  1. tsalexey544

    tsalexey544 New Member

    Joined:
    Nov 18, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    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:
    $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
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    You have to specify the full path to the directory!
     
  3. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:

Share This Page