php如何输出能让google浏览器直接播放的mp4文件

WBOY
Release: 2016-06-20 12:36:28
Original
2179 people have browsed it

如果我们直接把一个MP4文件放在服务器里,然后用google浏览器打开,浏览器会默认在线观看。
但是往往文件并不是那么赤裸裸的保存,如果是用php来输出mp4文件,试了很久,浏览器都会直接当作文件下载,而不会尝试在线播放。
刚开始以为是必须先要支持断线下载,然后改了一下,后来还是没用,浏览器还是默认直接当作文件下载。
不知道有没有大牛能解决这个让我头疼好久的问题。。


回复讨论(解决方案)

在php脚本里写html代码,用html5的video标签来解决播放问题

在php脚本里写html代码,用html5的video标签来解决播放问题


我并不想这样,如果是这样的话,那么手机就没法直接播放了。
这个问题我已经解决了,看下面

这个问题我已经解决了,代码如下

<?phpfunction PutMovie($file) {	header("Content-type: video/mp4");	header("Accept-Ranges: bytes");		$size = filesize($file);	if(isset($_SERVER['HTTP_RANGE'])){		header("HTTP/1.1 206 Partial Content");		list($name, $range) = explode("=", $_SERVER['HTTP_RANGE']);		list($begin, $end) =explode("-", $range);		if($end == 0) $end = $size - 1;	}	else {		$begin = 0; $end = $size - 1;	}	header("Content-Length: " . ($end - $begin + 1));	header("Content-Disposition: filename=".basename($file));	header("Content-Range: bytes ".$begin."-".$end."/".$size);	$fp = fopen($file, 'rb');	fseek($fp, $begin);	while(!feof($fp)) {		$p = min(1024, $end - $begin + 1);		$begin += $p;		echo fread($fp, $p);	}	fclose($fp);}putfile("1.mp4");?>
Copy after login

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!