Developer's Closet A place where I can put my PHP, SQL, Perl, JavaScript, and VBScript code.

Function to Format a Date in PHP

This is a really simple function to format a date.

function date_formatter($date) {
	return date("Y-m-d G:i:s",$date);
Tagged as: , No Comments
Output File Size in PHP

Pass a file size to this function like this:

$filesize = get_file_size(2048);

And return a nicely formatted file size:

2 MB

// function to get file size and present in human readable format
function get_file_size($size) {
	$sizes = Array(' B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB');
	$ext = $sizes[0];
	for ($i=1; (($i = 1024)); $i++) {
		$size = $size / 1024;
		$ext  = $sizes[$i];
	return number_format($size)." ".$ext;
Tagged as: , No Comments