Devone

How Could I Show File Sizes Next to an Upload After It's Been Selected?

Asked by Devone 2 years ago select file size upload


Autobots
0
 
The following function will help you get the file size, now you'll just have to find how to use CSS in order to position the file size at the right location.

/*
* @param string $file Filepath
* @param int $digits Digits to display
* @return string|bool Size (KB, MB, GB, TB) or boolean
*/

function getFilesize($file,$digits = 2) {
       if (is_file($file)) {
               $filePath = $file;
               if (!realpath($filePath)) {
                       $filePath = $_SERVER["DOCUMENT_ROOT"].$filePath;
       }
           $fileSize = filesize($filePath);
               $sizes = array("TB","GB","MB","KB","B");
               $total = count($sizes);
               while ($total-- && $fileSize > 1024) {
                       $fileSize /= 1024;
                       }
               return round($fileSize, $digits)." ".$sizes[$total];
       }
       return false;
}

by Autobots 2 years ago

Answer this question

How Could I Show File Sizes Next to an Upload After It's Been Selected?

0 errors found:

 
0