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 25651
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))));
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sunny Shah |
last post by:
hello php programmers & friends,
i want to limit the size of my folder. is there any code in php or
other language to check the size n limit it or display warning msg.
please guide me.
...
|
by: Hughs Man |
last post by:
I am using exchange 2003 now
Recently I was notified the harddisk is out of space.
Thus I remove part of the email of each folder and the public folder.
But the folder size doesn't trim down.
...
|
by: Kevin F |
last post by:
I'm trying to use the following code to get my remote server's folder
size information. Unfortunately, i'm getting the error:
Traceback (most recent call last):
File...
|
by: Kevin F |
last post by:
I'm trying to use the following code to get my remote server's folder
size information. Unfortunately, i'm getting the error:
Traceback (most recent call last):
File...
|
by: TyBreaker |
last post by:
I have a vbscript which returns the folder size of any folder instantly
by referring to Folder.Size. I don't need any iteration or recursion
through the subfolders, adding together individual file...
|
by: ethanhines |
last post by:
I am using MS Access 2007, I want to change the size of the Check Box that is displayed when a Value List is displayed for multiple selection. I changed the font size but I need to change the Check...
|
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= |
last post by:
Hi all
how can I get folder size with high performance ??
Do I need use recursive method for all files-subfolders within root folder
?? Anyway for do it ?? Perhaps using API Windows ??
...
|
by: Frinavale |
last post by:
Hi there!
I'm hoping that someone knows how to check the size of a file before it is uploaded to the server using JavaScript.
I have seen suggested solutions using an ActiveX control to check...
|
by: jeddiki |
last post by:
I want to check the size of an image file before I write it.
If it is a certain size, then I won't write it.
Can I check the future size of the file by
using strlen() on the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |