note 95305 added to function.disk-total-space

From: Date: Fri, 25 Dec 2009 14:52:24 +0000
Subject: note 95305 added to function.disk-total-space
Groups: php.notes 
Request: Send a blank email to php-notes+get-164323@lists.php.net to get a copy of this message
Something that might go well with this function is the ability to list available disks. On Windows, here's the relevant code: /** * 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; } } EXAMPLE OF USE: print_r(get_disks()); EXAMPLE RESULT: Array ( [1] => A:\ [2] => C:\ [3] => D:\ [4] => E:\ [5] => F:\ [6] => G:\ [7] => H:\ [8] => I:\ [9] => M:\ [10] => X:\ [11] => Z:\ ) Warning: This also finds empty disk drives (eg; CD or SMD drives or the more common floppy drive). Warning2: If you want to find space usage using the info from my function, prepend the disk function with the "@", eg: $free=@disk_free_space('A:\\'); ---- Server IP: 69.147.83.197 Probable Submitter: 195.158.85.58 ---- Manual Page -- http://www.php.net/manual/en/function.disk-total-space.php Edit -- https://master.php.net/note/edit/95305 Del: integrated -- https://master.php.net/note/delete/95305/integrated Del: useless -- https://master.php.net/note/delete/95305/useless Del: bad code -- https://master.php.net/note/delete/95305/bad+code Del: spam -- https://master.php.net/note/delete/95305/spam Del: non-english -- https://master.php.net/note/delete/95305/non-english Del: in docs -- https://master.php.net/note/delete/95305/in+docs Del: other reasons-- https://master.php.net/note/delete/95305 Reject -- https://master.php.net/note/reject/95305 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164323) next »