PHP如何使用disk_total_space()函数?代码示例

2021年3月31日17:33:09 发表评论 725 次浏览

PHP中的disk_total_space()函数是一个内置函数, 用于返回指定目录的总空间disk_total_space()函数表示总空间(以字节为单位)。它返回文件系统或磁盘分区上的总空间。

disk_total_space()函数返回作为字符串输入的指定目录的相应文件系统或磁盘分区上的字节总数。

语法如下:

float disk_total_space ( string $directory )

参数:PHP中的disk_total_space()函数仅接受一个参数$目录这是目录。

返回值:它返回文件系统或磁盘分区上的总空间。

错误与异常:

  1. 如果将文件名作为参数而不是目录, 则PHP中的disk_total_space()函数可能会给出不正确的结果。
  2. PHP中的disk_total_space()函数不适用于远程文件, 仅适用于服务器文件系统可访问的文件。

例子:

Input : disk_total_space("D:");
Output : 10969328844798729

Input : disk_total_space("C:");
Output : 104379834795739795

下面的程序说明了disk_total_space()函数:

程序1:

<?php
  
// specifying directory to check for total space
echo disk_total_space( "D:" );
  
?>

输出如下:

10969328844798729

程序2:

<?php
  
// specifying directory to
// check for total space
$space = disk_total_space( "C:" );
  
echo "C: drive has a total capacity
                     of $space bytes.";
  
?>

输出如下:

C: drive has a total capacity of 104379834795739795 bytes.

参考:

http://php.net/manual/en/function.disk-total-space.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: