Counting issue

  • seularts
  • Graduate
  • Graduate
  • User avatar
  • Posts: 153
  • Loc: Romania

Post 3+ Months Ago

Here is the code that counts all the image files from a group of folders in the binary folder. The problem is that when it counts the file, if i have 1 file in the first folder(88x31) and another one in a second folder (120x60) it will count 3 instead of 2. I have no clue where i went wrong :(

read.php
PHP Code: [ Select ]
<?php
    $path = "./binary/";
    $dir_handle = @opendir($path) or die("Unable to open $path");
   
   echo "<br /><br />Lista website-urilor existente:<br /><br />";
    while ($file = readdir($dir_handle)) {
    if($file == "." || $file == ".." || $file == "error_log" || $file == "light" || $file == "binary" || $file == "admin" || $file == "img" || preg_match("/\.htaccess/i",$file) || preg_match("/\.php/i",$file) || preg_match("/\.jpg/i",$file) || preg_match("/\.css/i",$file) )
        continue;
$filex='./binary/'.$file;
include 'count.php';
$filecountx = $filecount1 + $filecount2 + $filecount3 + $filecount4 + $filecount5 + $filecount6 + $filecount7 + $filecount8 + $filecount9 + $filecount10 + $filecount11 + $filecount12 + $filecount13 + $filecount14 + $filecount15;
 
        echo "- $file {".$filecountx."} <br /><br />";
    }
    closedir($dir_handle);
   ?>
   
 
 
  1. <?php
  2.     $path = "./binary/";
  3.     $dir_handle = @opendir($path) or die("Unable to open $path");
  4.    
  5.    echo "<br /><br />Lista website-urilor existente:<br /><br />";
  6.     while ($file = readdir($dir_handle)) {
  7.     if($file == "." || $file == ".." || $file == "error_log" || $file == "light" || $file == "binary" || $file == "admin" || $file == "img" || preg_match("/\.htaccess/i",$file) || preg_match("/\.php/i",$file) || preg_match("/\.jpg/i",$file) || preg_match("/\.css/i",$file) )
  8.         continue;
  9. $filex='./binary/'.$file;
  10. include 'count.php';
  11. $filecountx = $filecount1 + $filecount2 + $filecount3 + $filecount4 + $filecount5 + $filecount6 + $filecount7 + $filecount8 + $filecount9 + $filecount10 + $filecount11 + $filecount12 + $filecount13 + $filecount14 + $filecount15;
  12.  
  13.         echo "- $file {".$filecountx."} <br /><br />";
  14.     }
  15.     closedir($dir_handle);
  16.    ?>
  17.    
  18.  
  19.  


count.php
PHP Code: [ Select ]
<?php
$dir1 = $filex.'/88x31';
$filecount1 = 0;
$d1 = dir($dir1);
 
while ($f1 = $d1->read()) {
 if(strstr( $f1, '.htm' )) continue;
 if(strstr( $f1, '.php' )) continue;
 if(strstr( $f1, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f1!= '.') && ($f1!= '..')) {
 if(!is_dir($f1)) $filecount1++;
 }
}
 
 
$dir2 = $filex.'/120x60';
$filecount2 = 0;
$d2 = dir($dir2);
 
while ($f2 = $d2->read()) {
 if(strstr( $f2, '.php' )) continue;
 if(strstr( $f2, '.htm' )) continue;
 if(strstr( $f2, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f2!= '.') && ($f2!= '..')) {
 if(!is_dir($f2)) $filecount2++;
 }
}
 
 
$dir3 = $filex.'/120x90';
$filecount3 = 0;
$d3 = dir($dir3);
 
while ($f3 = $d3->read()) {
 if(strstr( $f3, '.php' )) continue;
 if(strstr( $f3, '.htm' )) continue;
 if(strstr( $f3, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f3!= '.') && ($f3!= '..')) {
 if(!is_dir($f3)) $filecount3++;
 }
}
 
$dir4 = $filex.'/120x240';
$filecount4 = 0;
$d4 = dir($dir4);
 
while ($f4 = $d4->read()) {
 if(strstr( $f4, '.php' )) continue;
 if(strstr( $f4, '.htm' )) continue;
 if(strstr( $f4, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f4!= '.') && ($f4!= '..')) {
 if(!is_dir($f4)) $filecount4++;
 }
}
 
$dir5 = $filex.'/120x600';
$filecount5 = 0;
$d5 = dir($dir5);
 
while ($f5 = $d5->read()) {
 if(strstr( $f5, '.php' )) continue;
 if(strstr( $f5, '.htm' )) continue;
 if(strstr( $f5, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f5!= '.') && ($f5!= '..')) {
 if(!is_dir($f5)) $filecount5++;
 }
}
 
$dir6 = $filex.'/125x125';
$filecount6 = 0;
$d6 = dir($dir6);
 
while ($f6 = $d6->read()) {
 if(strstr( $f6, '.php' )) continue;
 if(strstr( $f6, '.htm' )) continue;
 if(strstr( $f6, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f6!= '.') && ($f6!= '..')) {
 if(!is_dir($f6)) $filecount6++;
 }
}
 
$dir7 = $filex.'/160x600';
$filecount7 = 0;
$d7 = dir($dir7);
 
while ($f7 = $d7->read()) {
 if(strstr( $f7, '.php' )) continue;
 if(strstr( $f7, '.htm' )) continue;
 if(strstr( $f7, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f7!= '.') && ($f7!= '..')) {
 if(!is_dir($f7)) $filecount7++;
 }
}
 
$dir8 = $filex.'/180x150';
$filecount8 = 0;
$d8 = dir($dir8);
 
while ($f8 = $d8->read()) {
 if(strstr( $f8, '.php' )) continue;
 if(strstr( $f8, '.htm' )) continue;
 if(strstr( $f8, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f8!= '.') && ($f8!= '..')) {
 if(!is_dir($f8)) $filecount8++;
 }
}
 
$dir9 = $filex.'/234x60';
$filecount9 = 0;
$d9 = dir($dir9);
 
while ($f9 = $d9->read()) {
 if(strstr( $f9, '.php' )) continue;
 if(strstr( $f9, '.htm' )) continue;
 if(strstr( $f9, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f9!= '.') && ($f9!= '..')) {
 if(!is_dir($f9)) $filecount9++;
 }
}
 
$dir10 = $filex.'/240x400';
$filecount10 = 0;
$d10 = dir($dir10);
 
while ($f10 = $d10->read()) {
 if(strstr( $f10, '.php' )) continue;
 if(strstr( $f10, '.htm' )) continue;
 if(strstr( $f10, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f10!= '.') && ($f10!= '..')) {
 if(!is_dir($f10)) $filecount10++;
 }
}
 
$dir11 = $filex.'/250x250';
$filecount11 = 0;
$d11 = dir($dir11);
 
while ($f11 = $d11->read()) {
 if(strstr( $f11, '.php' )) continue;
 if(strstr( $f11, '.htm' )) continue;
 if(strstr( $f11, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f11!= '.') && ($f11!= '..')) {
 if(!is_dir($f11)) $filecount11++;
 }
}
 
$dir12 = $filex.'/300x250';
$filecount12 = 0;
$d12 = dir($dir12);
 
while ($f12 = $d12->read()) {
 if(strstr( $f12, '.php' )) continue;
 if(strstr( $f12, '.htm' )) continue;
 if(strstr( $f12, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f12!= '.') && ($f12!= '..')) {
 if(!is_dir($f12)) $filecount12++;
 }
}
 
$dir13 = $filex.'/336x280';
$filecount13 = 0;
$d13 = dir($dir13);
 
while ($f13 = $d13->read()) {
 if(strstr( $f13, '.php' )) continue;
 if(strstr( $f13, '.htm' )) continue;
 if(strstr( $f13, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f13!= '.') && ($f13!= '..')) {
 if(!is_dir($f13)) $filecount13++;
 }
}
 
$dir14 = $filex.'/468x60';
$filecount14 = 0;
$d14 = dir($dir14);
 
while ($f14 = $d14->read()) {
 if(strstr( $f14, '.php' )) continue;
 if(strstr( $f14, '.htm' )) continue;
 if(strstr( $f14, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f14!= '.') && ($f14!= '..')) {
 if(!is_dir($f14)) $filecount14++;
 }
}
 
$dir15 = $filex.'/728x90';
$filecount15 = 0;
$d15 = dir($dir15);
 
while ($f15 = $d15->read()) {
 if(strstr( $f15, '.php' )) continue;
 if(strstr( $f15, '.htm' )) continue;
 if(strstr( $f15, '_url' )) continue;
 if(strstr( $f1, '.sjx' )) continue;
 if(strstr( $f1, '.txt' )) continue;
 if(($f15!= '.') && ($f15!= '..')) {
 if(!is_dir($f15)) $filecount15++;
 }
}
 
?>
  1. <?php
  2. $dir1 = $filex.'/88x31';
  3. $filecount1 = 0;
  4. $d1 = dir($dir1);
  5.  
  6. while ($f1 = $d1->read()) {
  7.  if(strstr( $f1, '.htm' )) continue;
  8.  if(strstr( $f1, '.php' )) continue;
  9.  if(strstr( $f1, '_url' )) continue;
  10.  if(strstr( $f1, '.sjx' )) continue;
  11.  if(strstr( $f1, '.txt' )) continue;
  12.  if(($f1!= '.') && ($f1!= '..')) {
  13.  if(!is_dir($f1)) $filecount1++;
  14.  }
  15. }
  16.  
  17.  
  18. $dir2 = $filex.'/120x60';
  19. $filecount2 = 0;
  20. $d2 = dir($dir2);
  21.  
  22. while ($f2 = $d2->read()) {
  23.  if(strstr( $f2, '.php' )) continue;
  24.  if(strstr( $f2, '.htm' )) continue;
  25.  if(strstr( $f2, '_url' )) continue;
  26.  if(strstr( $f1, '.sjx' )) continue;
  27.  if(strstr( $f1, '.txt' )) continue;
  28.  if(($f2!= '.') && ($f2!= '..')) {
  29.  if(!is_dir($f2)) $filecount2++;
  30.  }
  31. }
  32.  
  33.  
  34. $dir3 = $filex.'/120x90';
  35. $filecount3 = 0;
  36. $d3 = dir($dir3);
  37.  
  38. while ($f3 = $d3->read()) {
  39.  if(strstr( $f3, '.php' )) continue;
  40.  if(strstr( $f3, '.htm' )) continue;
  41.  if(strstr( $f3, '_url' )) continue;
  42.  if(strstr( $f1, '.sjx' )) continue;
  43.  if(strstr( $f1, '.txt' )) continue;
  44.  if(($f3!= '.') && ($f3!= '..')) {
  45.  if(!is_dir($f3)) $filecount3++;
  46.  }
  47. }
  48.  
  49. $dir4 = $filex.'/120x240';
  50. $filecount4 = 0;
  51. $d4 = dir($dir4);
  52.  
  53. while ($f4 = $d4->read()) {
  54.  if(strstr( $f4, '.php' )) continue;
  55.  if(strstr( $f4, '.htm' )) continue;
  56.  if(strstr( $f4, '_url' )) continue;
  57.  if(strstr( $f1, '.sjx' )) continue;
  58.  if(strstr( $f1, '.txt' )) continue;
  59.  if(($f4!= '.') && ($f4!= '..')) {
  60.  if(!is_dir($f4)) $filecount4++;
  61.  }
  62. }
  63.  
  64. $dir5 = $filex.'/120x600';
  65. $filecount5 = 0;
  66. $d5 = dir($dir5);
  67.  
  68. while ($f5 = $d5->read()) {
  69.  if(strstr( $f5, '.php' )) continue;
  70.  if(strstr( $f5, '.htm' )) continue;
  71.  if(strstr( $f5, '_url' )) continue;
  72.  if(strstr( $f1, '.sjx' )) continue;
  73.  if(strstr( $f1, '.txt' )) continue;
  74.  if(($f5!= '.') && ($f5!= '..')) {
  75.  if(!is_dir($f5)) $filecount5++;
  76.  }
  77. }
  78.  
  79. $dir6 = $filex.'/125x125';
  80. $filecount6 = 0;
  81. $d6 = dir($dir6);
  82.  
  83. while ($f6 = $d6->read()) {
  84.  if(strstr( $f6, '.php' )) continue;
  85.  if(strstr( $f6, '.htm' )) continue;
  86.  if(strstr( $f6, '_url' )) continue;
  87.  if(strstr( $f1, '.sjx' )) continue;
  88.  if(strstr( $f1, '.txt' )) continue;
  89.  if(($f6!= '.') && ($f6!= '..')) {
  90.  if(!is_dir($f6)) $filecount6++;
  91.  }
  92. }
  93.  
  94. $dir7 = $filex.'/160x600';
  95. $filecount7 = 0;
  96. $d7 = dir($dir7);
  97.  
  98. while ($f7 = $d7->read()) {
  99.  if(strstr( $f7, '.php' )) continue;
  100.  if(strstr( $f7, '.htm' )) continue;
  101.  if(strstr( $f7, '_url' )) continue;
  102.  if(strstr( $f1, '.sjx' )) continue;
  103.  if(strstr( $f1, '.txt' )) continue;
  104.  if(($f7!= '.') && ($f7!= '..')) {
  105.  if(!is_dir($f7)) $filecount7++;
  106.  }
  107. }
  108.  
  109. $dir8 = $filex.'/180x150';
  110. $filecount8 = 0;
  111. $d8 = dir($dir8);
  112.  
  113. while ($f8 = $d8->read()) {
  114.  if(strstr( $f8, '.php' )) continue;
  115.  if(strstr( $f8, '.htm' )) continue;
  116.  if(strstr( $f8, '_url' )) continue;
  117.  if(strstr( $f1, '.sjx' )) continue;
  118.  if(strstr( $f1, '.txt' )) continue;
  119.  if(($f8!= '.') && ($f8!= '..')) {
  120.  if(!is_dir($f8)) $filecount8++;
  121.  }
  122. }
  123.  
  124. $dir9 = $filex.'/234x60';
  125. $filecount9 = 0;
  126. $d9 = dir($dir9);
  127.  
  128. while ($f9 = $d9->read()) {
  129.  if(strstr( $f9, '.php' )) continue;
  130.  if(strstr( $f9, '.htm' )) continue;
  131.  if(strstr( $f9, '_url' )) continue;
  132.  if(strstr( $f1, '.sjx' )) continue;
  133.  if(strstr( $f1, '.txt' )) continue;
  134.  if(($f9!= '.') && ($f9!= '..')) {
  135.  if(!is_dir($f9)) $filecount9++;
  136.  }
  137. }
  138.  
  139. $dir10 = $filex.'/240x400';
  140. $filecount10 = 0;
  141. $d10 = dir($dir10);
  142.  
  143. while ($f10 = $d10->read()) {
  144.  if(strstr( $f10, '.php' )) continue;
  145.  if(strstr( $f10, '.htm' )) continue;
  146.  if(strstr( $f10, '_url' )) continue;
  147.  if(strstr( $f1, '.sjx' )) continue;
  148.  if(strstr( $f1, '.txt' )) continue;
  149.  if(($f10!= '.') && ($f10!= '..')) {
  150.  if(!is_dir($f10)) $filecount10++;
  151.  }
  152. }
  153.  
  154. $dir11 = $filex.'/250x250';
  155. $filecount11 = 0;
  156. $d11 = dir($dir11);
  157.  
  158. while ($f11 = $d11->read()) {
  159.  if(strstr( $f11, '.php' )) continue;
  160.  if(strstr( $f11, '.htm' )) continue;
  161.  if(strstr( $f11, '_url' )) continue;
  162.  if(strstr( $f1, '.sjx' )) continue;
  163.  if(strstr( $f1, '.txt' )) continue;
  164.  if(($f11!= '.') && ($f11!= '..')) {
  165.  if(!is_dir($f11)) $filecount11++;
  166.  }
  167. }
  168.  
  169. $dir12 = $filex.'/300x250';
  170. $filecount12 = 0;
  171. $d12 = dir($dir12);
  172.  
  173. while ($f12 = $d12->read()) {
  174.  if(strstr( $f12, '.php' )) continue;
  175.  if(strstr( $f12, '.htm' )) continue;
  176.  if(strstr( $f12, '_url' )) continue;
  177.  if(strstr( $f1, '.sjx' )) continue;
  178.  if(strstr( $f1, '.txt' )) continue;
  179.  if(($f12!= '.') && ($f12!= '..')) {
  180.  if(!is_dir($f12)) $filecount12++;
  181.  }
  182. }
  183.  
  184. $dir13 = $filex.'/336x280';
  185. $filecount13 = 0;
  186. $d13 = dir($dir13);
  187.  
  188. while ($f13 = $d13->read()) {
  189.  if(strstr( $f13, '.php' )) continue;
  190.  if(strstr( $f13, '.htm' )) continue;
  191.  if(strstr( $f13, '_url' )) continue;
  192.  if(strstr( $f1, '.sjx' )) continue;
  193.  if(strstr( $f1, '.txt' )) continue;
  194.  if(($f13!= '.') && ($f13!= '..')) {
  195.  if(!is_dir($f13)) $filecount13++;
  196.  }
  197. }
  198.  
  199. $dir14 = $filex.'/468x60';
  200. $filecount14 = 0;
  201. $d14 = dir($dir14);
  202.  
  203. while ($f14 = $d14->read()) {
  204.  if(strstr( $f14, '.php' )) continue;
  205.  if(strstr( $f14, '.htm' )) continue;
  206.  if(strstr( $f14, '_url' )) continue;
  207.  if(strstr( $f1, '.sjx' )) continue;
  208.  if(strstr( $f1, '.txt' )) continue;
  209.  if(($f14!= '.') && ($f14!= '..')) {
  210.  if(!is_dir($f14)) $filecount14++;
  211.  }
  212. }
  213.  
  214. $dir15 = $filex.'/728x90';
  215. $filecount15 = 0;
  216. $d15 = dir($dir15);
  217.  
  218. while ($f15 = $d15->read()) {
  219.  if(strstr( $f15, '.php' )) continue;
  220.  if(strstr( $f15, '.htm' )) continue;
  221.  if(strstr( $f15, '_url' )) continue;
  222.  if(strstr( $f1, '.sjx' )) continue;
  223.  if(strstr( $f1, '.txt' )) continue;
  224.  if(($f15!= '.') && ($f15!= '..')) {
  225.  if(!is_dir($f15)) $filecount15++;
  226.  }
  227. }
  228.  
  229. ?>


Thanks for your time.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

is the variable filecount being set to 0 after traversing the directory structure? Might also be calling the same method without realising it. I would recommend checking the logic calling this code

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 65 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.