What are some common methods for extracting file extensions in PHP when working with image files?

When working with image files in PHP, it is common to need to extract the file extension in order to determine the type of image and handle it accordingly. One common method for extracting file extensions in PHP is to use the pathinfo() function, which returns an associative array containing information about a file path. By using pathinfo() with the PATHINFO_EXTENSION flag, you can easily extract the file extension from the file path.

// Example code to extract file extension using pathinfo()
$file_path = 'path/to/image.jpg';
$extension = pathinfo($file_path, PATHINFO_EXTENSION);

echo $extension; // Output: jpg