2016-09-07 3 views
0

재생할 수있는 .mp4 파일이 있으며이 코드를 사용하여 PHP를 사용하여 파일을 다운로드했습니다.PHP를 사용하여 웹에서 MP4를 다운로드 한 후 재생할 수 없음

웹 브라우저에서 파일을 다운로드 할 수 있지만 파일을 다운로드 한 후에는 재생할 수 없습니다.

코드에 문제가 있습니까?

<?php 
// place this code inside a php file and call it f.e. "download.php" 
$path = $_SERVER['DOCUMENT_ROOT'] . "/video/"; 
$fullPath = $path."test_video.mp4"; 

if ($fd = fopen ($fullPath, "r")) { 
    $fsize = filesize($fullPath); 
    $path_parts = pathinfo($fullPath); 
    header("Content-type: application/octet-stream"); 
    header("Content-Disposition: filename=\"".$path_parts["basename"]."\""); 
    header("Content-length: $fsize"); 
    header("Cache-control: private"); //use this to open files directly 
    while(!feof($fd)) { 
     $buffer = fread($fd, 2048); 
     echo $buffer; 
    } 
} 
fclose ($fd); 
exit; 
?> 
+0

[mcve] – xenteros

답변

0

먼저 header("Content-type: application/octet-stream");은 파일을 다운로드 할 필요가 없습니다. 이 작업을해야

header('Content-type: video/mp4'); 
header('Content-type: video/mpeg'); 

Source

둘째

변화 헤더.

+0

을 입력하십시오. 동영상/mp4로 변경 한 경우 동영상을 다운로드하는 대신 웹 브라우저에 표시합니다. – jeon

+1

브라우저에서 헤더를 강제로 다운로드 할 수 있습니다. 여기에 대한 답변보기 : http://stackoverflow.com/questions/21091766/mp4-download-causes-browser-to-play-file-instead-of-download –

0

나는 주석을 달 것을 요구하지 않는다. 텍스트 또는 이미지와 같은 다른 파일에 대한 코드를 확인하십시오. 오류가 발생해야합니다.

관련 문제