17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1062 Views |
-
get the size of a folder

7 June 2008 at 2:56pm
I have modify my folder.php in sapphire/filesystem/Folder
to be able to get the size of a folder directly with a folder object, I have ovverrides the function getAbsoluteSize of filethis is called reccursivily ion case of folder inside the folder..
//return the size in octet
public function getAbsoluteSize($path='')
{
if(empty($path))
{
$path = Director::baseFolder() . '/' . $this->getRelativePath();
}
$h = @opendir($path);
if($h==0)return 0;
$sf = 0;
while ($f = readdir($h))
{
if ( $f!= "..")
{
$nd = $path ."/". $f ;
if( $f!=".")
$sf += filesize( $nd );
if( $f!="." && is_dir($nd))
{
$nd = $path . $f ;
$sf+= $this->getAbsoluteSize( $nd );
}
}
}
closedir($h);
return $sf ;
}For information, you can do it also with a shell but this requires 751 CHmod on the folder (more access..less security)
$folder = "home/tea/mail/";if($pass === "eggnut") {
$job = shell_exec("du -s -k $folder"); //summary
echo "<b>SIZE in KB:</b> $job";
I do not like to change my core, for the further versionning.
But I do not need another class folder, and actually $Myfolder->getAbsoluteSize() exist and does not give the good result.If a guy of the core dev read this post do you think,; it culd be a good think to integreta this to the further versions.
Thanks.Your framework is awesome guys !
10 of people , developers & others
Mike
-
Re: get the size of a folder

7 June 2008 at 4:49pm Last edited: 7 June 2008 4:53pm
Hi there,
Thanks for the kind words of using SilverStripe, I hope development has been smooth for you and your team.
Thanks also for showing the function you have created for Folder.php. The typical work flow for a community member wishing to contribute code to the main branch is to submit a patch, using our open source tracker.
You can do that by visiting http://open.silverstripe.com, creating an account (if you haven't already), and hitting the "New ticket" button. You'll also want to select "Patch" from the Type dropdown, so we can recognise your ticket as a patch. From then, you'll probably see some comments in the ticket from a core developer if there are any questions about your code, or more information required.
Cheers!
Sean
| 1062 Views | ||
|
Page:
1
|
Go to Top |


