PHP下载MP3文件文件

新建文件download.php,键入以下代码:

<?php

$fileName = $_GET['file'];

$file = 'music/' . $fileName;

if (!file_exists($file)) {
    http_response_code(404);
    die();
}

header("Cache-Control: private");
header("Content-type: audio/mpeg3");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=".$fileName);
//So the browser can display the download progress
header("Content-Length: ".filesize($file));

readfile($file);