You might be able to use glob()
for your purposes. Supposing all pictures are in a directory named imgs
:
$user_imgs = count(glob('imgs/*'.$user_id.'*')));
$user_imgs
will contain the number of files in imgs
that have $user_id
in the file name.
You can get more creative with the pattern, if need be. This example just finds all files that have $user_id
anywhere in the file name. Up to you how specific you want to be regarding the pattern you are searching for.
UPDATE based on your attempted solution
You can simplify your algorithm to this:
$orderId = $_GET['orderid'];
$all_images = glob('uploads/'.$orderId.'*');
foreach($all_images as $i)
echo $i . '<br/>';
$totalImages = count($all_images);
echo '<hr>Total Images found for this ID '.$orderId.' = '.$totalImages;
echo '<hr>New count for image would be = '. ($totalImages+1);
UPDATE in consideration of new requirements
$orderId = $_GET['orderid'];
$all_images = glob('uploads/'.$orderId.'*');
$pp = $qc = 0;
foreach($all_images as $i) {
if (strpos($i, '-PP.')!==false)
$pp++;
elseif (strpos($i, '-QC.')!==false)
$qc++;
}
echo '<hr>Total Images found for this ID '.$orderId.' (PP) = '.$pp;
echo '<hr>New count for image would be = '. ($pp+1);
echo '<hr>Total Images found for this ID '.$orderId.' (QC) = '.$qc;
echo '<hr>New count for image would be = '. ($qc+1);