How to write a code for video streaming in php
Here's a simple example of how to stream a video file in PHP:
php<?php
// Specify the video file path
$file = 'path/to/video.mp4';
// Check if the file exists
if (file_exists($file)) {
// Set the appropriate headers for video streaming
header('Content-Type: video/mp4');
header('Content-Length: ' . filesize($file));
// Stream the video content
readfile($file);
exit;
} else {
// Handle the case if the file does not exist
header("HTTP/1.0 404 Not Found");
echo 'File not found';
exit;
}
?>
This code will read the specified video file and send its contents to the client using the appropriate Content-Type
and Content-Length
headers. The video content is streamed using the readfile
function. If the file does not exist, it will return a 404 Not Found error.
Comments
Post a Comment