본문 바로가기

[ Web Program ]/PHP / MySQL

PHP Code [ Disk Space (%), DB Space (%) ]


<!---------------------------------------------------------------------

*프로그램이름: Space Checker
*제작자: 조경진
*제작일:2003년6월3일
*용도: 자신의 계정을 어느 정도 사용했는지 확인할 수 있게 만든 프로그램
*연락처: Email: jstyle@empal.com
Website: http://jstyle.byus.net
MSN massenger: jstyle@empal.com

----------------------------------------------------------------------->
<?

//아래에 설정을 변경해 주세요.

//Disk config...
$disk_using = `du -sb`; //파일이 올라간 폴더의 용량을 측정하게 된는데, 만약 상위폴더의 용량을 측정하고 싶다면 $du=`du -sd ../`; 과 같이 수정해주시면 됩니다.
$disk_total = 500; //하드디스크 용량을 입력해주세요. MB단위로 적어주세요.

$disk_total = $disk_total*1024*1024; //MB -> Byte
$disk_free = $disk_total-$disk_using;
$r_disk_using = sprintf("%0.1f",$disk_using/$disk_total*100);
$r_disk_free = 100-$r_disk_using;

//DB config...
$db_host = "localhost"; //호스트네임을 입력하세요.
$db_database = "디비네임"; //디비네임을 입력하세요.
$db_user = "아이디"; //아이디을 입력하세요.
$db_pwd = "패스워드"; //패스워드를 입력하세요.
$db_total = 500; //디비 용량을 입력해주세요. MB단위로 적어주세요.

//이 아래부터는 설정할 부분이 없습니다.

$db_total = $db_total*1024*1024; //MB -> Byte

//db접속
$db_con = mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_database, $db_con);

//전체테이블현황을 불러오는 쿼리문
$result = mysql_query("SHOW TABLE STATUS", $db_con);
$db_using = 0;
while($dbData=mysql_fetch_array($result))
{
$db_using += $dbData[Data_length]+$dbData[Index_length];
}

$db_free = $db_total-$db_using;
$r_db_using = sprintf("%0.1f",$db_using/$db_total*100);
$r_db_free = 100-$r_db_using;


//파일크기를 KB, MB, etc 변환해서 리턴
function size($size)
{
if(!$size) return "0 Byte";
if($size<1024)
{
return ($size." Byte");
}
elseif($size >1024 && $size< 1024 *1024)
{
return sprintf("%0.1f KB",$size / 1024);
}
else return sprintf("%0.1f MB",$size / (1024*1024));
}


?>

<html>
<head>
<title>Space Checker // Disk <?=size($disk_using)?>, DB <?=size($db_using)?> </title>
<style>

<!--
TD {font-size:9pt;font-family:Verdana;color:666666}
A:link {color:666666;text-decoration:none;}
A:visited {color:666666;text-decoration:none;}
A:active {color:999999;text-decoration:none;}
A:hover {color:999999;text-decoration:none;}
-->

</style>
</head>

<body bgcolor="#000000" link="#999999" vlink="#999999" alink="#999999" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">


<table width="100%" border="0" height="100%">
<tr>
<td>
<div align="center">
<table width="500" cellspacing="0" cellpadding="20" style='table-layout:fixed;border:1 solid; border-color:#333333'>
<tr>
<td>


<div align="center">
<p><h3><i>Space Checker</i></h3></p>
<p>
<b><font size="2" color="#FFFFFF">*</font>Disk space</b><br>
Total <?=size($disk_total)?> | Using <font color="#999999"><?=size($disk_using)?>(<?=$r_disk_using?>%)</font> | Free <font color="#999999"><?=size($disk_free)?></font><br>
</p>

<table width="400" border="1" height="16" cellspacing="0" cellpadding="0" bordercolor="#333333" style=table-layout:fixed>
<tr>
<td width="<?=$r_disk_using?>%" style="filter=progid:DXImageTransform.Microsoft.Gradient(GradientType=<SPAN class=font-color2>0</SPAN>, StartColorStr=#000000, EndColorStr=#cccccc)">
</td>
<td width="<?=$r_disk_free?>%" bgcolor="#000000">
</td>
</tr>
</table>
<br>

<p>
<b><font size="2" color="#FFFFFF">*</font>DB space</b><br>
Total <?=size($db_total)?> | Using <font color="#999999"><?=size($db_using)?>(<?=$r_db_using?>%)</font> | Free <font color="#999999"><?=size($db_free)?></font>
</p>
<table width="400" border="1" height="16" cellspacing="0" cellpadding="0" bordercolor="#333333" style=table-layout:fixed>
<tr>
<td width="<?=$r_db_using?>%" style="filter=progid:DXImageTransform.Microsoft.Gradient(GradientType=<SPAN class=font-color2>0</SPAN>, StartColorStr=#000000, EndColorStr=#cccccc)">
</td>
<td width="<?=$r_db_free?>%" bgcolor="#000000">
</td>
</tr>
</table>
<p><A HREF="http://jstyle.byus.net" target="_blank">Created by JSTYLE</A></p>
</div> </td>
</tr>
</table>

</div>
</td>
</tr>
</table>


</body>
</html>