generating database m3u file

Asked by At

I am having trouble generating a .m3u file from the database

generate.php

<?php
include_once 'conexao.php';
$myfile = fopen("arquivo.m3u", "w") or die("Impossível abrir o ficheiro!");
$mainline = 
"#EXTM3U \n"; 
fwrite($myfile, $mainline);
$grab = $link->prepare("SELECT * FROM `tb_iptv`");
$grab->execute();
foreach($grab as $p) {
$canal = $p["canal"];
$url = $p["url"];   
$tvgid = $p["tvgid"];
$tvgname = $p["tvgname"];
$tvglogo = $p["tvglogo"];
$grupo = $p["grupo"];
$mainline2 ='#EXTINF:-1 tvg-id="'.$tvgid.'" tvg-name="'.$tvgname.'" tvg-logo="'.$tvglogo.'" group-title="'.$grupo.'",'.$canal.'
'.$url.'
';
fwrite($myfile, $mainline2);    
}
fclose($myfile);
echo file_get_contents("arquivo.m3u");
header("Content-Type: audio/mpegurl");
header("Content-Disposition: attachment; filename=lista_canais.m3u");
?>

Warning: include(conexao.php): failed to open stream: No such file or directory in C:\wamp64\www\cadastro\generate.php on line 2 Warning: include(): Failed opening 'conexao.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp64\www\cadastro\generate.php on line 2

Notice: Undefined variable: link in C:\wamp64\www\cadastro\generate.php on line 8 Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\wamp64\www\cadastro\generate.php on line 8 ( ! ) Error: Call to a member function prepare() on null in C:\wamp64\www\cadastro\generate.php on line 8

0 Answers