Well, if it works - but why haul preg_match in multiple times if you don't actually use any regular expressions? You don't even use case-insensitive matching, to be honest, because you strtolower() the filenames anyway.
I.e., why not just use one that reads
/.(gif|jpe?g)$/
Where the \ makes ure you match a . and not just any old character, and the $ makes sure you really are looking at the file extension and not something in the middle of the filename.
And "$variable" is just redundant extra work; just use $variable.