私のウェブサイトには次の表があります。
<table>
<tr>
<td>Song Name: Far-Sighted</td>
<td>
<a href=http://michaelpitluk.com/audio/far_sighted.mp3>Download</a>
</td>
</tr>
</table>
私の目標は、人々が「ダウンロード」をクリックすると、ブラウザが強制的に mp3 をダウンロードするようにすることです。
これを行うために必要なphpスクリプトを調査しましたが、それを曲のリンクに接続する方法がわかりません。
php ディレクトリの下に新しいファイルを作成し、それを download.php と呼び、スクリプトを挿入して、どうにかして曲を指すようにしますか?
これが私の曲にリンクしようとしているphpスクリプトです:
<?php
// Fetch the file info.
$filePath = '/path/to/file/on/disk.jpg';
if(file_exists($filePath)) {
$fileName = basename($filePath);
$fileSize = filesize($filePath);
// Output headers.
header("Cache-Control: private");
header("Content-Type: application/stream");
header("Content-Length: ".$fileSize);
header("Content-Disposition: attachment; filename=".$fileName);
// Output file.
readfile ($filePath);
exit();
}
else {
die('The provided file path is not valid.');
}
?>