Play mp4 file through php in HTML5 Video Tag in Chrome?
mp4, php, video
Solution
OK! I've resolved my problem :) Hope this will help anyone has the same problem as me
Just use that code:
$file = 'local_file';
$newfile = 'outFile';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($newfile));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
Problem
I have a problem with mp4 files. Html5 Video Tag can play it with direct link, but not with PHP Header (Mp3 is worked fine with PHP Header). I have tried almost of solution in Stack but still not resolve my problem :( Hear is my code: PHP mp4.php ``` error_reporting(0); $local_file = 'z.mp4';//'b.mp3'; $download_file = 'out.mp4'; // send headers header('Cache-control: private'); header('Content-Type: video/mp4'); header('Content-Length: '.filesize($local_file)); header('Content-Disposition: filename='.$download_file); header('Accept-Ranges: bytes'); header("Content-Transfer-Encoding: binary"); readfile($local_file); ``` HTML ``` <video controls="" autoplay="" name="media"> <source src="http://localhost/videos/mp4.php" type="video/mp4"> </video> ``` I don't know why :( Please help me. Thanks,