What are some common methods for streaming videos on a website using PHP?
Streaming videos on a website using PHP typically involves setting up a server-side script to handle video streaming and rendering the video player on the client-side. One common method is to use the HTML5 video tag along with PHP to serve the video content dynamically.
<?php
// Set the video file path
$video_path = 'path/to/video.mp4';
// Get the file size
$file_size = filesize($video_path);
// Set the content type header
header('Content-Type: video/mp4');
header('Content-Length: ' . $file_size);
// Open the video file
$fp = fopen($video_path, 'rb');
// Stream the video content
while (!feof($fp)) {
echo fread($fp, 8192);
ob_flush();
flush();
}
// Close the file
fclose($fp);
?>