What are some best practices for handling user input when it comes to specifying video file formats in PHP applications?

When handling user input for specifying video file formats in PHP applications, it is important to validate and sanitize the input to prevent potential security vulnerabilities such as file inclusion attacks or malicious file uploads. One best practice is to use a whitelist approach where only allowed file formats are accepted.

// Validate and sanitize user input for video file format
$allowedFormats = ['mp4', 'avi', 'mov'];

$userInput = $_POST['video_format']; // Assuming the input comes from a form field

if (in_array($userInput, $allowedFormats)) {
    // Process the video file format
    echo "Selected video format: " . $userInput;
} else {
    // Invalid input, handle error or display a message to the user
    echo "Invalid video format selected";
}