You are using incorrect syntax for your if statement. Use this:
if ($extension == 'jpg' || $extension == 'jpeg') {
Your example is evaluating ('jpg' || 'jpeg') as a boolean. Since a string evaluates to true in PHP, that statement is always correct.
$extension
then gets typecast to a boolean making your statement equivalent to (true == true)
.
Using the === operator will cause $extension
not to be typecast, so it will be ("some string value" === true)
which is false.