戻る

ディスクの残容量を調べる(参考)

disk_free_space()関数

ハードディスク上の残容量(空き容量)を調べるにはdisk_free_space()関数を使います。パーティション(またはファイルシステム)に対応する全体バイト数を返します。この関数では引数としてディレクトリ名を指定しますが、ディレクトリの容量ではなく、ディスクパーティション全体の残容量が返されます。返り値の単位は「バイト」です。

引数にディレクトリ名だけを指定した場合、カレントドライブの残容量が返されます。「disk_free_space("e:")のように特定のドライブ名を指定して、そのドライブの残容量を調べることもできます。

PHP

<?php
header("Content-type: text/html; charset=utf-8");

//ディスク残容量を取得
$spacebyte = disk_free_space(".");

echo number_format($spacebyte) ."バイトあります。<br>";

echo number_format($spacebyte / 1024) . "キロバイトあります。<br>";

echo number_format($spacebyte / pow(1024, 3)) . "ギガバイトあります。<br>";

//Dドライブの残容量を取得
echo number_format(disk_free_space("d:"));
?>

inserted by FC2 system