This is my script which count file size in folder "files" But in folder "files" there is subfolder ''screenshot'', how to set up script not to count files in subfolder ''screenshot'' <?php $maxupload=1024000000; // in byte $dir='files'; $notcount=array('index.html','listing.php','descriptionfile.txt','ddimgtooltip.js','Thumbs.db'); dirs($dir); $sizeinbyte=($_SESSION[tots]==0)?'0':$_SESSION[tots]; $_SESSION[tots]=array(); unset($_SESSION[tots]); function dirs($dir){ global $notcount; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if(is_dir($dir.'/'.$file)){ dirs($dir.'/'.$file); }else{ if (!in_array($file, $notcount)) { $fl=filesize($dir.'/'.$file); $_SESSION[tots]=$_SESSION[tots]+$fl; } } } } closedir($handle); } } ?> PHP:
Like this? $pos = strpos($dir,"screenshot"); if($pos === false) { $fl=filesize($dir.'/'.$file); $_SESSION[tots]=$_SESSION[tots]+$fl; } PHP:
Give this a try: <?php $maxupload=1024000000; // in byte $dir='files'; $notcount=array('index.html','listing.php','descriptionfile.txt','ddimgtooltip.js','Thumbs.db'); dirs($dir); $sizeinbyte=($_SESSION[tots]==0)?'0':$_SESSION[tots]; $_SESSION[tots]=array(); unset($_SESSION[tots]); function dirs($dir){ global $notcount; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if(is_dir($dir.'/'.$file)){ if ($file != "screenshot") { dirs($dir.'/'.$file); } }else{ if (!in_array($file, $notcount)) { $fl=filesize($dir.'/'.$file); $_SESSION[tots]=$_SESSION[tots]+$fl; } } } } closedir($handle); } } ?> PHP:
Do it just like this: the strpos function will determine the position of "screenshot" text string into the analysed and and will only count when the path doesn't contain it. I expect the rest of the code was working just fine. <?php $maxupload=1024000000; // in byte $dir='files'; $notcount=array('index.html','listing.php','descriptionfile.txt','ddimgtooltip.js','Thumbs.db'); dirs($dir); $sizeinbyte=($_SESSION[tots]==0)?'0':$_SESSION[tots]; $_SESSION[tots]=array(); unset($_SESSION[tots]); function dirs($dir){ global $notcount; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if(is_dir($dir.'/'.$file)){ dirs($dir.'/'.$file); }else{ if (!in_array($file, $notcount)) { $pos = strpos($dir,"screenshot"); if($pos === false) { $fl=filesize($dir.'/'.$file); $_SESSION[tots]=$_SESSION[tots]+$fl; } } } } } closedir($handle); } } ?> PHP: