Are there best practices for setting the Content-Type header in PHP to ensure proper video playback on different players?

When serving video files in PHP, it is important to set the Content-Type header correctly to ensure proper playback on different players. The Content-Type header specifies the type of data being sent, and for video files, it should be set to "video/mp4" for MP4 files, "video/webm" for WebM files, and "video/ogg" for Ogg files. This helps the browser and video player to interpret the content correctly and play the video without issues.

$videoFilePath = 'path/to/video.mp4';

$extension = pathinfo($videoFilePath, PATHINFO_EXTENSION);

switch ($extension) {
    case 'mp4':
        $contentType = 'video/mp4';
        break;
    case 'webm':
        $contentType = 'video/webm';
        break;
    case 'ogg':
        $contentType = 'video/ogg';
        break;
    default:
        $contentType = 'video/mp4';
}

header('Content-Type: ' . $contentType);
readfile($videoFilePath);