What potential issue did the user encounter when trying to modify the script to count JPG files?

The potential issue the user encountered when trying to modify the script to count JPG files is that the script may not correctly filter out only JPG files. To solve this issue, the user should modify the script to check the file extension of each file and only count files with the ".jpg" extension.

$directory = "path/to/directory";
$files = scandir($directory);
$count = 0;

foreach($files as $file){
    if(pathinfo($file, PATHINFO_EXTENSION) == "jpg"){
        $count++;
    }
}

echo "Number of JPG files: " . $count;