From: s-ko Date: Thu, 25 Sep 2014 21:51:40 +0000 (+0100) Subject: Added optional file size display X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=53ce79d11c8f09ea6863830afd9b62b8e6401d7f;p=simple-upload.git Added optional file size display --- diff --git a/index.php b/index.php index 74a3fa8..2952e39 100644 --- a/index.php +++ b/index.php @@ -27,6 +27,10 @@ listfiles => true, + // Display file sizes + listfiles_size => true, + + // Randomize file names (number of 'false') random_name_len => 10, @@ -72,6 +76,19 @@ echo ''; } + function FormatSize ($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]; + } + + if (isset($_FILES['file']) && strlen($_FILES['file']['name']) > 1) { $data['uploaded_file_name'] = basename($_FILES['file']['name']); $data['target_file_name'] = $data['uploaded_file_name']; @@ -292,8 +309,14 @@ $filename"; + if (!in_array($filename, array('.', '..', $data['scriptname']))) { + $size = ''; + + if ($settings['listfiles_size']) + $size = '(' . FormatSize(filesize($filename)) . ')'; + + echo "
  • $filename $size
  • "; + } ?>