PHP接口开发简单方法

2021年10月8日

我有一个PHP模块,是调用图片、音频、视频的连接地址的,但是想把它做为一个api接口来调用,以前折腾了很久不知道怎么弄,经过请教一些朋友,终于解决了。

/*
 * 输出播放地址
 * */
function player()
{
    $url = str_replace("video=", "", $_SERVER["QUERY_STRING"]);
    header("Content-Type: video/mp4");
    $file = video_media($url);
    header("Location: {$file}");
    return $file;
}

?>
<?php echo player(); ?>

 

重要的是header那两行,第一行是文件头信息,告诉客户端浏览器这个是什么文件,第二行的file变量是地址,直接把地址输出到客户端,然后客户端只需要使用相应的标签就可以调用了。

调用方法很简单

<video src="https://xxxxxxxxx/video.php?video=https://xxxxxxxxxx/xxxxxxxxxxxx" controls="controls"  autoplay   playsinline></video>


sicnature ---------------------------------------------------------------------
Your current IP address is: 35.168.113.41
Your IP address location: 美国弗吉尼亚阿什本
Your IP address country and region: 美国 美国
Your current browser is:
Your current system is:
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://www.myzhenai.com.cn/post/3943.html

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注