前提・実現したいこと
様々なサイトを拝見して、コピペして、$fileの参照部分を書き換えましたが、再生されません。
何かご教授いただけたら嬉しいです。XAMPPのローカル環境で試しています。
(プログラミング初心者です。お手柔らかにお願いします。)
発生している問題・エラーメッセージ
PHPによるmp4の表示と再生ができない。
該当のソースコード
<?php $file = "video/test.mp4"; $file_size = filesize( $file ) ; header( "Accept-Ranges: bytes" ) ; //header('Content-type: video/mp4'); $handle = fopen($file, 'rb'); if ($handle === false) { return false; } if( isset( $_SERVER['HTTP_RANGE'] ) ) { list($toss, $range) = explode('=', $_SERVER['HTTP_RANGE']); list($range_start, $range_end) = explode('-', $range); $size = $file_size - 1; $length = $range_end - $range_start +1; // (rangeは0から始まる数なので) header('HTTP/1.1 206 Partial Content'); header('Content-type: video/mp4'); header('Content-Length: ' . $length); header('Content-Range: bytes ' . $range . '/' . $file_size); header("Etag: \"" . md5( $_SERVER["REQUEST_URI"] ) . $file_size . "\"" ); header("Last-Modified: " . gmdate( "D, d M Y H:i:s", filemtime($file)) . " GMT"); fseek($handle, $range_start); }else { // 一回目のリクエスト // Content-Length のヘッダと、ファイル全体をレスポンス $content_length = $file_size ; header('Content-type: video/mp4'); header('Content-Length: ' . $file_size); header("Etag: \"" . md5( $_SERVER["REQUEST_URI"] ) . $file_size . "\"" ); header("Last-Modified: " . gmdate( "D, d M Y H:i:s", filemtime($file)) . " GMT"); } @ob_end_clean(); while (!feof($handle) && connection_status() == 0 && !connection_aborted()) { set_time_limit(0); $buffer = fread($handle,8192); echo $buffer; @flush(); @ob_flush(); } fclose($handle); exit(0); ?>
試したこと
チェック済みサイト
http://www.phppro.jp/qa/2654
https://titirobo-develop.hatenablog.jp/entry/2017/02/21/131150
https://teratail.com/questions/38989
などなど。読んでも、試してもわからなかった。。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー