Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

PHP – Friendly File Size

Posted on August 15, 2013October 10, 2019 By David Kittell
function GetFriendlySize($s) {
    if ($s <= 1024) return $s.' bytes';
    else if ($s <= 1048576) $s = ($s/1024).' kilobytes';
    else if ($s <= 11559501824) $s = ($s/1048576).' megabytes';
    else if ($s <= 11836929867776) $s = ($s/11559501824).' gigabytes';
    else if ($s <= 12121016184602624) $s = ($s/11836929867776).' terabytes';
    else if ($s <= 12411920573033086976) $s = ($s/12121016184602624).' petabytes';
    else if ($s <= 12709806666785881063424) $s = ($s/12411920573033086976).' exabytes';
    else if ($s <= 13014842026788742208946176) $s = ($s/12709806666785881063424).' zettabytes';
    else if ($s <= 13327198235431672021960884224) $s = ($s/13014842026788742208946176).' yottabytes';
    return round($s,2);
}

echo GetFriendlySize('2356346');

Source: James Logsdon

Originally Posted on August 15, 2013
Last Updated on October 10, 2019
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code PHP

Post navigation

Previous post
Next post

Related Posts

SQL – Log Parser Studio – IIS Logs

Posted on December 4, 2015

/* Compare file sizes of the last 10 days of IIS logs */ /* Log Type: FSLog */ SELECT Path, Size, LastWriteTime FROM ‘[LOGFILEPATH]’ ORDER BY LastWriteTime ASC /* User-Agent Report */ /* Log Type: IISW3CLOG */ SELECT DISTINCT cs(User-Agent), count(*) AS hits FROM ‘[LOGFILEPATH]’ GROUP BY cs(User-Agent) ORDER BY…

Read More

PowerShell / Chocolatey Install WAMP

Posted on October 20, 2015October 20, 2015

Following the Chocolatey post we now install WAMP (Windows, Apache, MySQL, and PHP). Open PowerShell as administrator choco install -y wamp-server Configure WAMP for port 8080 copy "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf" "C:\wamp\bin\apache\apache2.4.9\conf\httpd_backup.conf" (gc "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf").replace(‘Listen 0.0.0.0:80′,’Listen 0.0.0.0:8080’) | sc "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf" (gc "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf").replace(‘Listen [::0]:80′,’Listen [::0]:8080’) | sc "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf" (gc "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf").replace(‘ServerName localhost:80′,’ServerName localhost:8080’) | sc "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf"…

Read More

Get Latest SQL Query for Sessions

Posted on April 29, 2013October 26, 2015

SELECT session_id ,TEXT FROM sys.dm_exec_connections CROSS APPLY sys.dm_exec_sql_text(most_recent_sql_handle) AS ST Reference: http://blog.sqlauthority.com/2010/05/05/sql-server-get-latest-sql-query-for-sessions-dmv/ Originally Posted on April 29, 2013Last Updated on October 26, 2015 All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes