Fix file extension check with pathinfo instead of basename