رد جديد  مشاركة جديدة 
كيفية معرفة حجم مجلد معين بالكيلوبايت
الكاتب الرسالة
Pepo
عضو مميز



المشاركات : 5,096
مجموعة : الاعضاء
الإنتساب : 30-12-2006
الحالة : غير متصل
السمعة : 37
الرد : #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); 



منقول للفائدة
غير مسموح بعرض الروابط الا بعد التسجيل و تفعيل العضوية

اخر مواضيعى

مع التحية Pepo
لولا ان لهذا المنتدى اخوة واخوات مثلكم.. ما كان له وجود حتى الأن
احبكم فى الله
2007-03-21 06:25 PM
زيارة موقع العضو إعرض جميع مشاركات العضو إقتبس الرسالة فى رد

رد جديد  مشاركة جديدة 
كيفية معرفة حجم مجلد معين بالكيلوبايت

إحتمالات التقييم ...
المشاركة : الكاتب الردود : المشاهدات : آخر رد
  معرفة عدد الملفات في مجلد معين Pepo 0 358 2007-03-21 06:29 PM
آخر رد: Pepo
  درس كيفية جلب اي بي للزائر Pepo 0 465 2007-03-21 05:32 PM
آخر رد: Pepo

إشترك بالمشاركة | إضافة المشاركة للمفضلة
الذهاب إلى :