재생할 수있는 .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;
?>
[mcve] – xenteros