以下のコードを使用して、サーバーから mp3 ファイルをダウンロードしています。コードはローカル システム (Windows OS) で正常に動作しています。
ただし、コードをサーバー (Linux) に移動すると、ファイルが見つからないというエラーが発生します。ファイルパスが正しく、ファイルが読み取り可能であると確信しています
if ($fd = fopen ($filePath, "r")) {
$fsize = filesize($filePath);
$path_parts = pathinfo($filePath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "mp3":
header("Content-type: audio/mpeg"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$originalFileName."\""); // use 'attachment' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$originalFileName."\"");
}
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)