Make mp3 seekable PHP

后端 未结 2 1817
情歌与酒
情歌与酒 2020-11-29 04:35

I did this PHP script


    $file_name = \'sample.mp3\';

    header(\'Content-Type: audio/mpeg\');

    $opts     = array(\'http\' =>
                      array         


        
2条回答
  •  一生所求
    2020-11-29 04:56

    This should hopefully fix your problem, follow this method.

    What you need to do is use readfile() and set file_exists() so that you can tell you're opening the correct file.

    $extension = "mp3";
    $mime_type = "audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3";
    
    if(file_exists($file_name)){
        header('Content-type: ' . $mime_type);
        header('Content-length: ' . filesize($file_name));
        header('Content-Disposition: filename="' . $file_name);
        header('X-Pad: avoid browser bug');
        header('Cache-Control: no-cache');
        readfile($file_name);
    }
    

    Reference

提交回复
热议问题