hello sir,
i have php code to display the following details.

Total size : 1.9 MB
No. of files : 15
No. of directories : 2

but i need to do this by database because i am displaying links from database.
so how it is possible. any suggestions please......... thank you.....
how to display

Can you display the code so we can see what is going on.

By Database you mean to get the info out from the db (table colum) instead of Manual PHP.
If that the case provide your source let's see.
Otherwise you can just clear the question again

Member Avatar for diafol

Not sure why you'd do this. Directories are usually dynamic, that is, files are added or deleted from them as a rule. So storing static data (a snapshot, if you like) about them in a database is probably not a fair representation of the directory as it is 'currently'.

Perhaps I've got the wrong end of the stick?

Perhaps the DB is updated when you add/delete a file?

here is the code. 
    function getDirectorySize($path)
      $totalsize = 0;
      $totalcount = 0;
      $dircount = 0;
      if ($handle = opendir ($path))
        while (false !== ($file = readdir($handle)))
          $nextpath = $path . '/' . $file;
          if ($file != '.' && $file != '..' && !is_link ($nextpath))
            if (is_dir ($nextpath))
              $result = getDirectorySize($nextpath);
              $totalsize += $result['size'];
              $totalcount += $result['count'];
              $dircount += $result['dircount'];
            elseif (is_file ($nextpath))
              $totalsize += filesize ($nextpath);
      closedir ($handle);
      $total['size'] = $totalsize;
      $total['count'] = $totalcount;
      $total['dircount'] = $dircount;
      return $total;

    function sizeFormat($size)
            return $size." bytes";
        else if($size<(1024*1024))
            return $size." KB";
        else if($size<(1024*1024*1024))
            return $size." MB";
            return $size." GB";



    echo "Total size : ".sizeFormat($ar['size'])."<br>";
    echo "No. of files : ".$ar['count']."<br>";
    echo "No. of directories : ".$ar['dircount']."<br>"; 


You can use this query to sum yout table size

SELECT table_name AS "Table", 
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" 
FROM information_schema.TABLES 
WHERE table_schema = "$DB_NAME"
 AND table_name = "$TABLE_NAME";

And about your directory and file.. i need to know your table schema

Member Avatar for diafol

I'm not sure what you're trying to do with the code. You can traverse and sum dir details - OK. But, you want to store this snapshot in a db table? I'm still at a loss...

just i want to show the information of folders to the users, thats it. and its not mandatory right...... ok thanks for the replies......

Member Avatar for diafol

and its not mandatory right......

Sorry, I don't understand.

Anyway, are you looking at storing the data such as....


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.