This doesn't make any fucking sense. So I have this human readable filesize function:
function read_size($bytes, $file)
{
$kB = 1024;
$MB = $kB * 1024;
$GB = $MB * 1024;
$TB = $GB * 1024;
if(!is_file($file))
{
return "Directory";
}
elseif(is_file($file))
{
switch($bytes)
{
case $bytes < $kB:
return $bytes . ' B';
break;
case $bytes >= $kB && $bytes < $MB:
return round($bytes / $kB, 2) . ' KB';
break;
case $bytes >= $MB && $bytes < $GB:
return round($bytes / $MB, 2) . ' MB';
break;
case $bytes >= $GB && $bytes < $TB:
return round($bytes / $GB, 2) . ' GB';
break;
case $bytes >= $TB:
return round($bytes / $TB, 2) . ' TB';
break;
}
}
}
Also just to be thorough, here's where I call the function:
<tr>
<td><?php echo $file; ?></td>
<td><?php echo read_size(filesize($path_and_file), $file); ?></td>
<td><?php echo view_perms($file); ?></td>
And at first glance it seems to work fine. It works just fine in the directory that it shows the contents of by default. However, when I back out to any other directory it says that everything is a directory. I just created a .txt file and in the filesize area it just said Directory instead of showing the filesize. I don't think that makes any fucking sense can you guys see a problem in my function?