0

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
    $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);
	?>

count.php

<?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++;
 } 
} 

?>

Thanks for your time.

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by rch1231
0

I would try outputting the individual variables and see if you can find out where the total is going wrong. Any reason you would not use something like this?

<?php
$output = `find ./binary -iname '*.jpg' -print | wc -l ` ;
echo "Total JPG files $output"; ?>

and get the OS to do the work?

0

yes.. i have to use different counts for each folder in binary.

0

fixed it.. i forget to change the &f element with the numbers at most of the counts in count.php :P well ups.. but thanks for the reply

0

Cool but I had another script based oon the KISS principal (Keep it simple, stupid)

<?php

$dirs = array("88x31","120x60","120x90","300x250");
for ($x=0; $x < count($dirs); $x++) {
    $output = `find ./binary/$dirs[$x] -iname '*.jpg' -print | wc -l ` ;
    echo "Total in $dirs[$x]  is $output <br>";
    $Totalall = $Totalall + $output;
}
echo "Grand Total is $Totalall";
?>

Edited by rch1231: spelling

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.