How can PHP developers ensure that uploaded files are in the correct format?

To ensure that uploaded files are in the correct format, PHP developers can use the `$_FILES` superglobal array to access the uploaded file information, including the file type. They can then validate the file type against a list of allowed file formats before processing or saving the file.

// Check if file was uploaded
if(isset($_FILES['file'])){
    $file = $_FILES['file'];
    
    // Define allowed file formats
    $allowedFormats = array('jpg', 'jpeg', 'png');
    
    // Get file extension
    $fileExt = pathinfo($file['name'], PATHINFO_EXTENSION);
    
    // Check if file format is allowed
    if(in_array($fileExt, $allowedFormats)){
        // File format is correct, process or save the file
    } else {
        // File format is not allowed, display an error message
        echo "Invalid file format. Allowed formats: jpg, jpeg, png";
    }
}