What is the best practice for assigning file extensions to original files in PHP when uploading images?

When uploading images in PHP, it is important to assign the correct file extension to the original files to ensure they can be properly identified and accessed later on. One common approach is to use the `pathinfo()` function to extract the file extension from the uploaded file's name and then assign it to the original file.

// Get the file extension from the uploaded file
$originalFileName = $_FILES['file']['name'];
$extension = pathinfo($originalFileName, PATHINFO_EXTENSION);

// Rename the uploaded file with the correct file extension
$originalFilePath = 'uploads/' . uniqid() . '.' . $extension;
move_uploaded_file($_FILES['file']['tmp_name'], $originalFilePath);

// Now $originalFilePath contains the uploaded file with the correct file extension