d
Amit DhamuSoftware Engineer
 

List System Drives

2 minute read 00000 views
function get_disks() {
    if (php_uname('s')=='Windows NT') {
        // windows
        $disks = `fsutil fsinfo drives`;
        $disks = str_word_count($disks, 1);

        if ($disks[0] != 'Drives') {
            return ''
        };

        unset($disks[0]);

        foreach ($disks as $key=>$disk){
            $disks[$key] = $disk . ':';
        }
        return $disks;
    } else {
        // unix
        $data = `mount`;
        $data = explode(' ', $data);
        $disks = [];
        foreach ($data as $token) {
            if (substr($token, 0, 5) == '/dev/') {
                $disks[] = $token;
            }
        }
        return $disks;
    }
}

/**
 * Usage
 */
print_r(get_disks());

/**
 * Result
 */
Array
(
    [1] => A:
    [2] => C:
    [3] => D:
)

Credits