hi dear experts,
hope you can help about checking the folder size,for example how many kilobytes is it already in PHP script...is it possible?
please help..thank you
10 25448
This little snippet, by Jonas Sweden in the PHP documentation, adds the sizes of all files in the folder and show the total bytes. - <?php
-
$path = "gal";
-
echo "Folder $path = ".filesize_r($path)." bytes";
-
-
function filesize_r($path){
-
if(!file_exists($path)) return 0;
-
if(is_file($path)) return filesize($path);
-
$ret = 0;
-
foreach(glob($path."/*") as $fn)
-
$ret += filesize_r($fn);
-
return $ret;
-
}
-
?>
Ronald :cool:
thank you very much sir ronverdonk...i will try the code right away...
OT: i read some threads, hehe...you like motoma? peace!!! :)
This little snippet, by Jonas Sweden in the PHP documentation, adds the sizes of all files in the folder and show the total bytes. - <?php
-
$path = "gal";
-
echo "Folder $path = ".filesize_r($path)." bytes";
-
-
function filesize_r($path){
-
if(!file_exists($path)) return 0;
-
if(is_file($path)) return filesize($path);
-
$ret = 0;
-
foreach(glob($path."/*") as $fn)
-
$ret += filesize_r($fn);
-
return $ret;
-
}
-
?>
Ronald :cool:
thank you thank you thank you sir ronverdonk...IT WORKS!!! :) good luck about..... :)
Code works fantastically!
Depending on the size of a folder, is it possible to display the size value in MegaBytes, GigaBytes, or TeraBytes, including the appropriate abbreviations MB, GB, TB
Code works fantastically!
Depending on the size of a folder, is it possible to display the size value in MegaBytes, GigaBytes, or TeraBytes, including the appropriate abbreviations MB, GB, TB
Divide the bytes by 1024 to get kilobytes -
$_bytes = $_FILES['file']['size'];
-
echo ($_bytes / 1024) . "Kb";
-
Code works fantastically!
Depending on the size of a folder, is it possible to display the size value in MegaBytes, GigaBytes, or TeraBytes, including the appropriate abbreviations MB, GB, TB
Thanks you KINGMAX. That's what we are here for.
And to wrap it up: here a little function that shows you the size in Gb, Mb, Kb or plain bytes.You can work out the Terabytes for yourself. - function showSize($size_in_bytes) {
-
$value = 0;
-
if ($size_in_bytes >= 1073741824) {
-
$value = round($size_in_bytes/1073741824*10)/10;
-
return ($round) ? round($value) . 'Gb' : "{$value} gB";
-
} else if ($size_in_bytes >= 1048576) {
-
$value = round($size_in_bytes/1048576*10)/10;
-
return ($round) ? round($value) . 'Mb' : "{$value} mB";
-
} else if ($size_in_bytes >= 1024) {
-
$value = round($size_in_bytes/1024*10)/10;
-
return ($round) ? round($value) . 'Kb' : "{$value} kB";
-
} else {
-
return "$size_in_bytes bytes";
-
}
-
}
Ronald
Thanks you KINGMAX. That's what we are here for.
And to wrap it up: here a little function that shows you the size in Gb, Mb, Kb or plain bytes.You can work out the Terabytes for yourself. - function showSize($size_in_bytes) {
-
$value = 0;
-
if ($size_in_bytes >= 1073741824) {
-
$value = round($size_in_bytes/1073741824*10)/10;
-
return ($round) ? round($value) . 'Gb' : "{$value} gB";
-
} else if ($size_in_bytes >= 1048576) {
-
$value = round($size_in_bytes/1048576*10)/10;
-
return ($round) ? round($value) . 'Mb' : "{$value} mB";
-
} else if ($size_in_bytes >= 1024) {
-
$value = round($size_in_bytes/1024*10)/10;
-
return ($round) ? round($value) . 'Kb' : "{$value} kB";
-
} else {
-
return "$size_in_bytes bytes";
-
}
-
}
Ronald
how will the whole script looks like?
What script? This is just a sample you can use in your own application to show the size of folders. You'll have to write the script, in which you want to use it, yourself.
Ronald
how will the whole script looks like?
-
<?php
-
$path = "myTargetedFolderNameHere"; // <-- Edit: Add your folder name here!
-
-
function filesize_r($path){ // Function 1
-
if(!file_exists($path)) return 0;
-
if(is_file($path)) return filesize($path);
-
$ret = 0;
-
foreach(glob($path."/*") as $fn)
-
$ret += filesize_r($fn);
-
return $ret;
-
}
-
-
function showSize($size_in_bytes) { // Function 2
-
$value = 0;
-
if ($size_in_bytes >= 1073741824) {
-
$value = round($size_in_bytes/1073741824*10)/10;
-
return ($round) ? round($value) . 'Gb' : "{$value} Gb";
-
} else if ($size_in_bytes >= 1048576) {
-
$value = round($size_in_bytes/1048576*10)/10;
-
return ($round) ? round($value) . 'Mb' : "{$value} Mb";
-
} else if ($size_in_bytes >= 1024) {
-
$value = round($size_in_bytes/1024*10)/10;
-
return ($round) ? round($value) . 'Kb' : "{$value} Kb";
-
} else {
-
return "{$size_in_bytes} Bytes";
-
}
-
}
-
-
echo "Folder {$path} size: <b>".showSize(filesize_r($path))."</b>";
-
?>
-
I found this in the web one day and it works fine for me. -
function getSymbolByQuantity($bytes)
-
{
-
$symbols = array('B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb');
-
$exp = floor(log($bytes)/log(1024));
-
-
return sprintf("%.2f " . $symbols[$exp], ($bytes/pow(1024, floor($exp))));
-
}
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
1 post
views
Thread by Sunny Shah |
last post: by
|
4 posts
views
Thread by Hughs Man |
last post: by
|
reply
views
Thread by Kevin F |
last post: by
|
1 post
views
Thread by Kevin F |
last post: by
|
3 posts
views
Thread by TyBreaker |
last post: by
| |
4 posts
views
Thread by =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= |
last post: by
| | | | | | | | | | | | |