是否可以从 PHP 获取特殊的本地磁盘信息?

发布于 2024-10-12 03:13:38 字数 84 浏览 12 评论 0原文

我在本地计算机上运行我的PHP代码,所以,我只想知道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.

Thank you very much!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

雄赳赳气昂昂 2024-10-19 03:13:38

内置函数:

如果您需要更多,可以通过 system()

对于磁盘使用情况,您还可以在网上找到不同的片段,例如:

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:

眼前雾蒙蒙 2024-10-19 03:13:38

此外,是的,可以检索此信息,因为您可以执行命令。还有一些 PHP 函数可以检索有关磁盘的信息,请查看以下链接:

然而,检索磁盘的名称需要使用命令来完成。我刚刚在 VirtualBox 中启动了 Windows,似乎以下内容可以工作:

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

Volumenaam 是荷兰语“Volumename”的意思。我只有荷兰语版本的 Windows,因此您必须检查实际的字符串是什么。

祝你好运。

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.

只怪假的太真实 2024-10-19 03:13:38

在您在这里提问之前,您是否尝试搜索过 PHP 手册?

这两个函数对我来说很快就出现了:

更多数据,例如光盘名称可能会更棘手(您可能需要按照此处的另一个答案使用 system() ),但这应该给您一个开始。

但请注意,当 PHP 在网站中运行时,它的功能会受到相当多的限制;它可能仅限于其本地 Web 文件夹才能进行任何光盘访问。

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.

清欢 2024-10-19 03:13:38

对于磁盘名称,您可以使用此函数

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

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");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文