jacko310592 Posted November 12, 2009 Share Posted November 12, 2009 hey guys, at the moment im trying to get my code to count two things [*]a full image count of images within the directory [*]image count of images with '[' at the start of the image name (these images are inside the same dir as the full image count i want to do) for the counts, i have the following code: $imageCount = count(glob("{*.JPG,*.jpg}")); $notForPurchaseCount = count(glob("{[*.JPG,[*.jpg}")); now, the thing is, i want to make it so if the full image count ($imageCount) equals the same as the $notForPurchaseCount, then it will out put a message stating that no images are available the full code i have so far, (which doesnt work correctly) is as follows: <?php $imageCount = count(glob("{*.JPG,*.jpg}")); $notForPurchaseCount = count(glob("{[*.JPG,[*.jpg}")); { if ($imageCount=='.$notForPurchaseCount.') echo'No Images in this Album are Available for Purchase'; } ?> i cant see where ive gone wrong here, can someone please help me thanks Link to comment https://forums.phpfreaks.com/topic/181244-counting-files/ Share on other sites More sharing options...
Garethp Posted November 12, 2009 Share Posted November 12, 2009 Oh God. My eyes started bleeding when I saw that code. No offense. Here's some working lines. Compare the difference <?php $imageCount = count(glob("{*.JPG,*.jpg}")); $notForPurchaseCount = count(glob("{[*.JPG,[*.jpg}")); if ($imageCount==$notForPurchaseCount) { echo 'No Images in this Album are Available for Purchase'; } ?> Link to comment https://forums.phpfreaks.com/topic/181244-counting-files/#findComment-956147 Share on other sites More sharing options...
jacko310592 Posted November 12, 2009 Author Share Posted November 12, 2009 thanks for the reply Garethp, but for some reason, although your code looks asif it should work fine, it doesnt seem to be doing it :/ but like 2mins ago i managed to work out a code which does work: <?php $imageCount = count(glob("*.jpg")); $notForPurchaseCount = count(glob("[*.jpg")); $count = ($imageCount - $notForPurchaseCount); { if ($count=="0") echo 'No Images in this Album are Available for Purchase'; else echo ''; } ?> the only thing is with the above though is that i cant get it to work with more than one file ext, like before i had {*.JPG,*.jpg} but thats not working this time. anyone any ideas why? Link to comment https://forums.phpfreaks.com/topic/181244-counting-files/#findComment-956155 Share on other sites More sharing options...
Garethp Posted November 12, 2009 Share Posted November 12, 2009 try "*(.jpg|.JPG|.png)" I'm not sure if the Glob pattern is the same as the regex pattern though, so I don't know if it'll work Link to comment https://forums.phpfreaks.com/topic/181244-counting-files/#findComment-956159 Share on other sites More sharing options...
jacko310592 Posted November 12, 2009 Author Share Posted November 12, 2009 also doesnt seem to be working :/ thanks for the reply though (: Link to comment https://forums.phpfreaks.com/topic/181244-counting-files/#findComment-956165 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.