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!!
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!!
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:
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:
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.
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.
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");