function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . ' ' . $units[$pow];
}
Tag Archive for size
formatBytes
Use Linux Find and Awk to Locate Large Files
find / -type f -size +20000k -exec ls -lh {} ; | awk '{ print $NF ": " $5 }'
Sort folders by size
du --max-depth=1 /home/ | sort -n -r
Web.config – define max. upload size
<system.web> <httpRuntime maxRequestLength="10000" /> </system.web> // size is in kilobytes // default upload size iz 4 megabytes // max upload size is 100 megabytes
FF default headline sizes and their 1.2em equivalents
h1 {display: block;font-size: 2em;font-weight: bold;margin: .67em 0;} // 32px
h2 {display: block;font-size: 1.5em;font-weight: bold;margin: .83em 0;} // 24px
h3 {display: block;font-size: 1.17em;font-weight: bold;margin: 1em 0;} // 19px
h4 {display: block;font-weight: bold;margin: 1.33em 0;} // 16px
h5 {display: block;font-size: 0.83em;font-weight: bold;margin: 1.67em 0;} // 13px
h6 {display: block;font-size: 0.67em;font-weight: bold;margin: 2.33em 0;} // 11px
h1 {font-size:2.667em;}
h2 {font-size:2em;}
h3 {font-size:1.583em;}
h4 {font-size:1.333em;}
h5 {font-size:1.083em;}
h6 {font-size:0.917em;}
Calculate directory size
/**
* Calculate directory size.
* @param string $path without trailing '/' or '' (eg. '/users/sampleUser', not '/users/sampleUser/')
* @return int size in bytes
*/
function calc_dir_size($path)
{
$size = 0;
if ($handle = opendir($path))
{
while (false !== ($entry = readdir($handle)))
{
$current_path = $path . '/' . $entry;
if ($entry != '.' && $entry != '..' && !is_link($current_path))
{
if (is_file($current_path))
$size += filesize($current_path);
elseif (is_dir($current_path))
$size = calc_dir_size($current_path);
}
}
}
closedir($handle);
return $size;
}
Get the width and height of an image using a function in PHP
<?php
list($width, $height, $type, $attr) = getimagesize("image_name.jpg");
echo "Image width " .$width;
echo "<BR>";
echo "Image height " .$height;
echo "<BR>";
echo "Image type " .$type;
echo "<BR>";
echo "Attribute " .$attr;
?>