Amit Dhamu

Writes Code

List System Drives

<?php 
/** 
 * Finds a list of disk drives on the server. 
 * @return array The array velues are the existing disks. 
 */ 
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=array(); 
        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


drives / hard drive / disks / php

← Remove Empty Lines In SublimeText Case Insensitive In Array Check →