search for in the  
<disk_free_spacediskfreespace>
Last updated: Thu, 19 May 2005

disk_total_space

(PHP 4 >= 4.1.0, PHP 5)

disk_total_space -- Returns the total size of a directory

Description

float disk_total_space ( string directory )

Given a string containing a directory, this function will return the total number of bytes on the corresponding filesystem or disk partition.

Example 1. disk_total_space() example

<?php
// $df contains the total number of bytes available on "/"
$df = disk_total_space("/");

// On Windows:
disk_total_space("C:");
disk_total_space("D:");
?>

Note: This function will not work on remote files as the file to be examined must be accessible via the servers filesystem.

See also disk_free_space()



User Contributed Notes
disk_total_space
mistake at e-mail dot ru
09-Jan-2005 04:28
Yeah, it works fine in most cases.
But in BSD you should use: explode("\t", $res);
;)
jensgrasnick5 at hotmail dot com
29-Nov-2003 02:00
Hi there. I do a little function with returns the occupied Space in bytes :

<?php
function disk_occupied_space($dir) {
 
$total = disk_total_space($dir) or die("Not attainable!");
 
$free = disk_free_space($dir);
 
$ges = $total - $free;
  return
$ges;
}
?>

I hope you can need it maybe ;-)
shalless at rubix dot net dot au
16-Jul-2003 09:36
My first contribution. Trouble is the sum of the byte sizes of the files in your directories is not equal to the amount of disk space consumed, as andudi points out. A 1-byte file occupies 4096 bytes of disk space if the block size is 4096. Couldn't understand why andudi did $s["blksize"]*$s["blocks"]/8. Could only be because $s["blocks"] counts the number of 512-byte disk blocks not the number of $s["blksize"] blocks, so it may as well just be $s["blocks"]*512. Furthermore none of the dirspace suggestions allow for the fact that directories are also files and that they also consume disk space. The following code dskspace addresses all these issues and can also be used to return the disk space consumed by a single non-directory file. It will return much larger numbers than you would have been seeing with any of the other suggestions but I think they are much more realistic:

function dskspace($dir)
{
   $s = stat($dir);
   $space = $s["blocks"]*512;
   if (is_dir($dir))
   {
     $dh = opendir($dir);
     while (($file = readdir($dh)) !== false)
       if ($file != "." and $file != "..")
         $space += dskspace($dir."/".$file);
     closedir($dh);
   }
   return $space;
}
tnugster at yahoo dot com
02-Jul-2002 04:08
I had trouble with getting the right size of my disk (on a linux server, dunno what kind of). I fixed it this way: (copy paste of my code)

//Note: Diskspace is calculated this way : diskspace / ((1024 * 1024 * 1024)) / 4) The / 4 is needed to get the proper values.

$df = floor(diskfreespace(".") / 268435456);
$total = floor(disk_total_space(".") / 268435456);
$used = $total - $df;

END

The / 4 did it for me, really weird but hey, it works now :)
andudi at gmx dot ch
11-Jun-2002 05:15
To find the total size of a file/directory you have to differ two situations:
(on Linux/Unix based systems only!?)

you are interested:
1) in the total size of the files in the dir/subdirs
2) what place on the disk your dir/subdirs/files uses

- 1) and 2) normaly differs, depending on the size of the inodes
- mostly 2) is greater than 1) (in the order of any kB)
- filesize($file) gives 1)
- "du -ab $file" gives 2)

so you have to choose your situation!

on my server I have no rights to use "exec du" in the case of 2), so I use:
  $s = stat($file);
  $size = $s[11]*$s[12]/8);
whitch is counting the inodes [12] times the size of them in Bits [11]

hopes this helps to count the used disk place in a right way... :-)

                     Andreas Dick
kit at 4me dot ru
28-Jun-2001 04:57
I just did the simple thing -

function Du($dir)
{
       $du = popen("/usr/bin/du -sk $dir", "r");
       $res = fgets($du, 256);
       pclose($du);
       $res = explode(" ", $res);
       return $res[0];
}

<disk_free_spacediskfreespace>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT