Use pathinfo instead of string operations to get file extension