Files::formatSize PHP Method

formatSize() public method

Format the file size, limits to Mb.
public formatSize ( integer $size ) : string
$size integer the raw filesize
return string formated file size.
    function formatSize($size)
    {
        if ($size < 1024) {
            return $size . ' bytes';
        } else {
            if ($size >= 1024 && $size < 1024 * 1024) {
                return sprintf('%01.2f', $size / 1024.0) . ' Kb';
            } else {
                return sprintf('%01.2f', $size / (1024.0 * 1024)) . ' Mb';
            }
        }
    }

Usage Example

Beispiel #1
0
/**
 * Draw the files in an table.
 */
function drawFiles($list, &$manager)
{
    global $relative;
    foreach ($list as $entry => $file) {
        ?>
		<td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block">
		<a href="javascript:;" onclick="selectImage('<?php 
        echo $file['relative'];
        ?>
', '<?php 
        echo $entry;
        ?>
', <?php 
        echo $file['image'][0];
        ?>
, <?php 
        echo $file['image'][1];
        ?>
);"title="<?php 
        echo $entry;
        ?>
 - <?php 
        echo Files::formatSize($file['stat']['size']);
        ?>
"><img src="<?php 
        echo $manager->getThumbnail($file['relative']);
        ?>
" alt="<?php 
        echo $entry;
        ?>
 - <?php 
        echo Files::formatSize($file['stat']['size']);
        ?>
"/></a>
		</td></tr><tr><td class="edit">
			<a href="images.php?dir=<?php 
        echo $relative;
        ?>
&amp;delf=<?php 
        echo rawurlencode($file['relative']);
        ?>
" title="Trash" onclick="return confirmDeleteFile('<?php 
        echo $entry;
        ?>
');"><img src="img/edit_trash.gif" height="15" width="15" alt="Trash"/></a><a href="javascript:;" title="Edit" onclick="editImage('<?php 
        echo rawurlencode($file['relative']);
        ?>
');"><img src="img/edit_pencil.gif" height="15" width="15" alt="Edit"/></a>
		<?php 
        if ($file['image']) {
            echo $file['image'][0] . 'x' . $file['image'][1];
        } else {
            echo $entry;
        }
        ?>
		</td></tr></table></td> 
	  <?php 
    }
    //foreach
}
All Usage Examples Of Files::formatSize