WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : File size with label - afunction that reads the filesize from a selected file and convert the number of bytes into KB, MB etc
Categories : PHP, Filesystem Click here to Update Your Picture
Olaf Lederer
Date : Dec 08th 2004
Grade : 3 of 5 (graded 2 times)
Viewed : 3785
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Olaf Lederer
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

This function reads the filesize from a selected file and convert the number of bytes into KB, MB etc. Just define the file and the path and the size is give by the function.

<?php
// the $file without the path, put the path in the $path-variable (based on the doc. root)
function file_size($file, $path = "") {
    global
$DOCUMENT_ROOT;
   
$bytes = array("B", "KB", "MB", "GB", "TB", "PB");
   
$file_with_path = $DOCUMENT_ROOT."/".$path."/".$file;
   
// replace (possible) double slashes with a single one
   
$file_with_path = str_replace("//", "/", $file_with_path);
   
$size = filesize($file_with_path);
   
$i = 0;
    while (
$size >= 1024) { //divide the filesize (in bytes) with 1024 to get "bigger" bytes
       
$size = $size/1024;
       
$i++;
    }
    if (
$i > 1) {
       
// you can change this number if you like (for more precision)
       
return round($size,1)." ".$bytes[$i];
    } else {
        return
round($size,0)." ".$bytes[$i];
    }
}
?>


Usage Example
[code]
<?php
// example for using
echo file_size("example.txt", "myFolder");
?>



Unix Disk Information with graphs
Categories : PHP, Shell Scripting, Filesystem
directory, opendir, listfiles, files in a directory, get directory
Categories : PHP, Filesystem
Show Source with Line Numbers
Categories : PHP, Regexps, Filesystem
How to find the name of the current file?
Categories : PHP, Filesystem, Strings
Opening and formatting text files into HTML on the fly- or HTML from templates.
Categories : PHP, HTML and PHP, Filesystem
GuestBook Light - a plug and play application for any website.
Categories : PHP, Complete Programs, Filesystem, Sessions
Relative Path
Categories : PHP, Filesystem
Image Browser
Categories : Filesystem, GD image library, Content Management, PHP
Differences between two files
Categories : PHP, Filesystem, Tip
Random Image Display
Categories : PHP, Filesystem, Graphics, HTML and PHP
Handle multiple file upload
Categories : Complete Programs, Filesystem, PHP, HTML and PHP
Directory viewer, customize how you display the file structure, easy to understand. Found out about PHP 3 days ago, and this is my first prog.
Categories : HTML and PHP, Complete Programs, Directories, Filesystem, PHP
basename -- Returns filename component of path
Categories : PHP, PHP Functions, Filesystem
Link Submition - Allow your visitors to submit links to the site.
Categories : PHP, Arrays, Filesystem, Beginner Guides
A simple configuration file editor to ease you life in setting up php applications. Reads variables from a given file automatically and displays current value. New value will be written to file after submit.
Categories : PHP, Filesystem, Regexps, Java Script