2

I am running my PHP code on my local computer,So ,I just want to know the PHP has any functions to get the local hard disk information.Such as the disk name , disk space,free space available .etc.

Thank you very much!!

imz -- Ivan Zakharyaschev
  • 4,730
  • 6
  • 50
  • 103
qinHaiXiang
  • 5,371
  • 10
  • 45
  • 60

5 Answers5

4

Builtins:

If you need more, you can access local commands via system().

For disk usage, you'll also find different snippets on the net, e.g. this:

miku
  • 172,072
  • 46
  • 300
  • 307
  • Thanks,and what kind of local commands should I use to get what I wants.Another program or windows' command?? And where to output the outcome?On the web page or whatever? I am not good at PHP,so please give me some more information. Thank you very much! – qinHaiXiang Jan 17 '11 at 14:00
2

There are two functions: disk_free_space() and disk_total_space().

powtac
  • 39,317
  • 26
  • 112
  • 166
1

In addition, yes, it is possible to retrieve this information, because you can execute commands. There are a few PHP functions to retrieve information about the disk as well, check out the following links:

Retrieving the disk's name, however, needs to be done with a command. I've just booted Windows in VirtualBox and it seems the following would work:

if( preg_match( '~Volumenaam : (.*)~i', `fsutil fsinfo volumeinfo C:\\`, $matches ) ) {
    echo $matches[1];
}

Volumenaam is Dutch for "Volumename". I only have the Dutch version of Windows, so you'd have to check what the actual string is.

Good luck.

Berry Langerak
  • 17,965
  • 4
  • 42
  • 55
0

Did you try searching the PHP manual before you asked here?

These two functions came up very quickly for me:

Further data such as the disc name may be trickier (you may need to use system() as per another answer here), but that should give you a start.

However, note that when PHP is running in a web site, it will have quite a lot of restrictions on what it can do; it's likely to be restricted to its local web folders for any disc access.

Spudley
  • 161,975
  • 39
  • 229
  • 303
  • thanks.I tried it via google search and maybe my wrong keywords,I didn't get what I want.So, I thought I should ask someone to get my first step ahead. – qinHaiXiang Jan 17 '11 at 14:03
0

For the Disk Name you can use this function

function GetVolumeLabel($drive) {
  // Try to grab the volume name
  if (preg_match('#Volume in drive [a-zA-Z]* is (.*)\n#i', shell_exec('dir '.$drive.':'), $m)) {
    $volname = ' ('.$m[1].')';
  } else {
    $volname = '';
  }
return $volname;
}

echo GetVolumeLabel("c");