Jump to content

Counting Files?


jacko310592

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.