What are best practices for setting the Content-Type header when serving video files in PHP?
When serving video files in PHP, it is important to set the correct Content-Type header to ensure that the browser interprets the file correctly. This header informs the browser of the type of content being served, allowing it to handle the file appropriately. To set the Content-Type header for video files, you can use the header() function in PHP with the value "video/mp4" for MP4 files, "video/webm" for WebM files, or "video/ogg" for Ogg files.
// Set the Content-Type header for MP4 video file
header('Content-Type: video/mp4');
// Set the Content-Type header for WebM video file
header('Content-Type: video/webm');
// Set the Content-Type header for Ogg video file
header('Content-Type: video/ogg');