The disk_free_space() function in PHP returns the amount of free space available on a disk or partition. If it always reads from the boot partition, it might be because the function is not given the correct path to the disk or partition you want to check.

The disk_free_space() function requires the path to the disk or partition as its parameter. If you don't provide any path, it will return the free space on the partition where the PHP script is executing, which could be the boot partition.

To fix this issue and get the free space from the desired disk or partition, you need to pass the correct path as an argument to the disk_free_space() function. Here's how you can do it:

php
// Replace '/path/to/disk/or/partition' with the actual path you want to check $diskFreeSpace = disk_free_space('/path/to/disk/or/partition'); // Display the result echo "Free space on the disk/partition: " . $diskFreeSpace . " bytes";

For example, to get the free space on the root partition in Linux, you can use the following code:

php
$diskFreeSpace = disk_free_space('/'); // Display the result echo "Free space on the root partition: " . $diskFreeSpace . " bytes";

Make sure to replace '/path/to/disk/or/partition' with the actual path to the disk or partition you want to check.

Keep in mind that the disk_free_space() function might not work correctly on some platforms or configurations, so it's essential to verify the result and test it on your specific environment to ensure accurate behavior. Additionally, ensure that the PHP script has the necessary permissions to read information from the disk or partition you are checking.

Have questions or queries?
Get in Touch