我有一個可播放的.mp4文件,我使用此代碼使用PHP下載文件。使用PHP從網上下載MP4後無法播放MP4
網絡瀏覽器下載文件確定,但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