تحديث آخر نسخة 1.8.37

تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
كيفية معرفة حجم مجلد معين بالكيلوبايت
#1
السلام عليكم ورحمة الله

لجلب حجم أي مجلد على السيرفر
بطريقة سهلة وواضحة
تستخدم الدالة التالية

PHP كود :
<?php
// ------------ lixlpixel recursive PHP functions -------------
// recursive_directory_size( directory, human readable format )
// expects path to directory and optional TRUE / FALSE
// PHP has to have the rights to read the directory you specify
// and all files and folders inside the directory to count size
// if you choose to get human readable format,
// the function returns the filesize in bytes, KB and MB
// ------------------------------------------------------------
 
// to use this function to get the filesize in bytes, write:
// recursive_directory_size('path/to/directory/to/count');
 
// to use this function to get the size in a nice format, write:
// recursive_directory_size('path/to/directory/to/count',TRUE);
 
function recursive_directory_size($directory$format=FALSE)
{
    $size 0;
 
    // if the path has a slash at the end we remove it here
    if(substr($directory,-1) == '/')
    {
        $directory substr($directory,0,-1);
    }
 
    // if the path is not valid or is not a directory ...
    if(!file_exists($directory) || !is_dir($directory) || !is_readable($directory))
    {
        // ... we return -1 and exit the function
       return -1;
    }
    // we open the directory
    if($handle opendir($directory))
    {
        // and scan through the items inside
        while(($file readdir($handle)) !== false)
        {
           // we build the new path
            $path $directory.'/'.$file;
 
            // if the filepointer is not the current directory
            // or the parent directory
            if($file != '.' && $file != '..')
            {
                // if the new path is a file
                if(is_file($path))
                {
                    // we add the filesize to the total size
                    $size += filesize($path);
 
                // if the new path is a directory
                }elseif(is_dir($path))
                {
                    // we call this function with the new path
                    $handlesize recursive_directory_size($path);
 
                    // if the function returns more than zero
                    if($handlesize >= 0)
                    {
                        // we add the result to the total size
                        $size += $handlesize;
 
                    // else we return -1 and exit the function
                    }else{
                        return -1;
                    }
                }
            }
        }
        // close the directory
        closedir($handle);
    }
     // if the format is set to human readable
     if($format == TRUE)
     {
         // if the total size is bigger than 1 MB
         if($size 1048576 1)
         {
             return round($size 10485761).' MB';
 
         // if the total size is bigger than 1 KB
         }elseif($size 1024 1)
         {
            return round($size 10241).' KB';
 
         // else return the filesize in bytes
         }else{
             return round($size1).' bytes';
         }
     }else{
         // return the total filesize in bytes
         return $size;
     }
 }
 
// ------------------------------------------------------------
?>

ويكون استخدامها كالتالي:
PHP كود :
recursive_directory_size('path/to/directory/to/count',TRUE); 


منقول للفائدة
http://lixlpixel.org/recursive_function/...cursively/
والتعريب
للأمانة منقول من منتدى بى اتش بى
الرد
شكر من طرف :


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 2 ) ضيف كريم