]> git.mxchange.org Git - simple-upload.git/commitdiff
Added optional file size display
authors-ko <aleks@s-ko.net>
Thu, 25 Sep 2014 21:51:40 +0000 (22:51 +0100)
committers-ko <aleks@s-ko.net>
Thu, 25 Sep 2014 21:51:40 +0000 (22:51 +0100)
index.php

index 74a3fa88c321b9c067e0bc93e7f01560e7367ca0..2952e39b0c1744f729e853b3b9b5f6f5c43a5101 100644 (file)
--- a/index.php
+++ b/index.php
                listfiles => true,
 
 
+               // Display file sizes
+               listfiles_size => true,
+
+
                // Randomize file names (number of 'false')
                random_name_len => 10,
 
                echo '</pre>';
        }
 
+       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'];
                                <?php
                                        $dh = opendir($settings['uploaddir']);
                                        while (false !== ($filename = readdir($dh)))
-                                               if (!in_array($filename, array('.', '..', $data['scriptname'])))
-                                                       echo "<li><a href=\"$filename\">$filename</a></li>";
+                                               if (!in_array($filename, array('.', '..', $data['scriptname']))) {
+                                                       $size = '';
+
+                                                       if ($settings['listfiles_size'])
+                                                               $size = '(' . FormatSize(filesize($filename)) . ')';
+
+                                                       echo "<li><a href=\"$filename\">$filename $size</a></li>";
+                                               }
                                ?>
                        </ul>
                <?php } ?>