January 28

Holding Pages

By Jamesy, 11:16 pm

rss comments feed slider open

I’ve got quite a few subdomains I haven’t finished yet. One is my old image uploader running a modified Cheverato. When I reinstalled my server OS (as Gentoo and I don’t get along) I decided to recode it from scratch myself and thus, it has been left with a php error for about 4 months now.

I also figured it was time to get organised in the way I store files. My haphazard method of just making any random directory and uploading to it is just plain silly, so I made a new sub-server. Which brings me to the splash pages, I just wanted something simple but with more than just a plain background. Ended up writing this little function which takes a total value which I know to be 1024MB per virtualhost on here, and outputting the free space, the total and a percentage in an array which can be plugged into very simple CSS in order to create a graph.

function free_space_graph() {
	$path = getcwd();
	$free = exec("du -c -a $path");
	$total = 1048576;
	$percentage = $free * 100 / $total;
	$details = array("free" => $free, "total" => $total, "percentage" => $percentage);
		return $details;
}

The CSS is simply


#graph {
width:400px;
margin: 10px auto;
height:25px;
position:absolute;
bottom:6px;
left:56px;
background:url(/graph-bg.png);
overflow:hidden;
}

#percentage {
height:25px;
background:url(/progress-bar.png);
}

#graph-text {
color:#fff;
width:400px;
height:25px;

line-height:25px;
text-align:center;
position:absolute;
bottom:17px;
left:56px;
z-index:2;
}

Easily plugged into:

$percentage = free_space_graph();
$width = round($percentage['percentage'], 0);
$total = $percentage['total'] / 1024;
Using: % out of MB

So yeah, you can see it in action at: http://uploads.shizzlenizzle.biz/ and http://files.shizzlenizzle.biz/

*Note, the CSS is a bit specific to my pages but should be simple enough to work out. All you need is the main #graph div to be around the inner #percentage div.

Leave a Reply

Spam Protection by WP-SpamFree Plugin