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

前提是你 提交于 2019-12-22 13:30:55

问题


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!!


回答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:

  • 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.




回答2:


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().



回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/4713893/is-it-possible-to-get-special-local-disk-information-from-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!