Home > Backend Development > PHP Tutorial > PHP从服务器请求完视频数据,如何显示?HTML5的video标签播放不了.

PHP从服务器请求完视频数据,如何显示?HTML5的video标签播放不了.

WBOY
Release: 2016-06-23 13:21:44
Original
1229 people have browsed it

以下是PHP在服务器端,得到数据后返回给浏览器的代码。

    <?php    header("Content-type:text/html;charset=utf-8");    $file_name=$_GET['fileName'];	//用以解决中文不能显示出来的问题	$file_name=iconv("utf-8","gb2312",$file_name);	$file_sub_path="/test/";	$file_path=$file_sub_path.$file_name;	//首先要判断给定的文件存在与否	if(!file_exists($file_path)){	echo "没有该文件文件";	return ;	}	header('Content-Description: File Transfer');	header('Content-Type: application/octet-stream');	header('Content-Disposition: attachment; filename='.basename($file_path));	header('Content-Transfer-Encoding: binary');	header('Expires: 1');	header('Cache-Control: must-revalidate');	header('Pragma: public');	header('Content-Length: ' . filesize($file_path));	ob_clean();	echo readfile($file_path);	exit;   ?>
Copy after login


前端显示视频代码。
<body>    <form id="form1" runat="server">        <img   src="http://111.121.22.141/download.php?fileName=/images/Chrysanthemum.jpg"     style="max-width:90%"  style="max-width:90%" alt="PHP从服务器请求完视频数据,如何显示?HTML5的video标签播放不了." ></img>        <video width="320" height="240" controls="controls" preload="auto" autoplay="autoplay" >        	<source src="http://111.121.22.141/download.php?fileName=/video/traveltaipei.mp4" type="video/mp4">        </video>        <audio controls="controls">  <source src="http://111.121.22.141/download.php?fileName=/voice/SleepAway.mp3"> </audio><!--         <embed widht="300" height="240" src="http://111.121.22.141/download.php?fileName=/video/traveltaipei.mp4" ></embed> -->    </form></body>
Copy after login


img标签能直接显示请求到的图片数据, audio标签能显示请求到的音频的时间,但是播放不了。 video标签一样只能显示出视频时间,播放不了。而用 embed标签,直接就把视频下载到本地了,在页面上没法播放。

请问我应该使用什么标签才能实现,在页面上播放视频和音频?或者如何修改PHP的返回数据流代码?


回复讨论(解决方案)

技术大拿们,快来帮帮我吧!

大神们都跑哪H去了

不会吧,CSDN的大神们都不在吗?

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template