我试图用curl获取m3u文件。该文件作为服务器响应的附件,如下所示:Content-Disposition: attachment; filename="myfile.m3u"
。
在我的php页面中使用curl,我需要获取该m3u文件,更改其内容并将更改的内容作为新的m3u文件返回。
<?php
ini_set('display_errors', 1);
//add these to make your php file a downloadable m3u.
//Without this VLC won't know how to process it.
//header('Content-Type: audio/x-mpegurl');
//header("Content-Transfer-Encoding: Binary");
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HEADER, 1);
//curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
//curl_setopt($ch, CURLINFO_CONTENT_TYPE, "application/octet-stream");
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$info = curl_getinfo($ch);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = 'myurltogetfile';
$fileContent = file_get_contents_curl($url);
echo $fileContent;
?>
有什么想法吗?
谢谢你!