开发者

Is it possible to get special Local Disk information from PHP?

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.

Tha开发者_开发知识库nk you very much!!


Builtins:

  • disk_free_space()
  • disk_total_space()

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:

  • http://justynshull.com/2010/08/du2-php/, which uses shell_exec().


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:

  • disk_total_space( $directory );
  • disk_free_space( $directory );

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.


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


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

These two functions came up very quickly for me:

  • disk_total_space()
  • disk_free_space()

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.


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜