Get the free space function for a Windows disk

Source: Internet
Author: User

<?PHP/** Get the remaining space on a disk * $param associative array, the subscript is which disk, unit, can be B,KB,MB,GB * can be set to get multiple disks, for example: Array (' C ' = = ' KB ', ' D ' = = ' mb ', ' E ' + ' GB ') ' F ' = ' B ') * If there is an error, return false*/    functionSpace ($arr){        //Check Parameters        if(Is_array($arr)){            //Initialize stored values            $memory=Array(); foreach($arr  as $disk=$size){                $D=Strtoupper($disk).‘:‘;//keyboard path converted to uppercase                $S=Strtoupper($size);//units converted to uppercase                if(In_array($D,Array(' C: ', ' D: ', ' E: ', ' F: ')) &&In_array($S,Array(' B ', ' KB ', ' MB ', ' GB ', ' TB ')))){                    Switch($S){                         Case' B ':$memory[$disk]=Disk_free_space($D).‘ B;  Break;  Case' KB ':$d=round(Disk_free_space($D)/1024); $memory[$disk] =$d.‘ KB ';  Break;  Case' MB ':$d=round(Disk_free_space($D) /POW(1024,2)); $memory[$disk]=$d.‘ MB ';  Break;  Case' GB ':$d=round(Disk_free_space($D) /POW(1024,3)); $memory[$disk]=$d.‘ GB ';  Break;  Case' TB ':$d=sprintf("%.4f",Disk_free_space($D) /POW(1024,4)); $memory[$disk] =$d.‘ TB ';  Break; default:return0;  Break; }                }Else{                    return NULL; }            }            return $memory; }Else{            return NULL; }    }    $arr=Array(' c ' = ' = ' kb ', ' d ' = ' Mb ', ' e ' = ' Gb ', ' f ' = ' Tb '); Var_dump(Space ($arr));

Get the free space function for a Windows disk

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.