How to serve m3u8 files with php?

by edmond_brakus , in category: PHP General , 9 months ago

How to serve m3u8 files with php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lily , 5 months ago

@edmond_brakus 

To serve m3u8 files with PHP, you can follow these steps:

  1. Create a PHP file (e.g., "server.php") in the same directory as your m3u8 files.
  2. In the "server.php" file, write the following PHP code to read the m3u8 file and serve it as a response:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<?php
// Specify the path to the m3u8 file
$m3u8_file = 'your_file.m3u8';

// Set the appropriate content type header
header('Content-Type: application/vnd.apple.mpegurl');

// Output the contents of the m3u8 file
readfile($m3u8_file);
?>


  1. Save the changes and upload the PHP file and m3u8 files to your web server.
  2. Access the m3u8 file using the URL to the "server.php" file in your web browser or media player.


This PHP code will serve the m3u8 file as a response with the correct content type header, allowing it to be played or downloaded by a media player that supports HLS (HTTP Live Streaming) protocol.