Skip to content

Instantly share code, notes, and snippets.

@harini-ua
Last active June 20, 2017 12:14
Show Gist options
  • Save harini-ua/0bce4bd77aae62c567ff63ccbbcdd2d3 to your computer and use it in GitHub Desktop.
Save harini-ua/0bce4bd77aae62c567ff63ccbbcdd2d3 to your computer and use it in GitHub Desktop.
Laravel Helper Pack
<?php
/**
* Return sizes readable by humans
*/
function human_filesize($bytes, $decimals = 2)
{
$size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB'];
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) .
@$size[$factor];
}
/**
* Is the mime type an image
*/
function is_image($mimeType)
{
return starts_with($mimeType, 'image/');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment