On the web page with the link to the file, create the php tag:
a href='download.php?name=myfile.mp3
&path=music/myfile.mp3'
Second, create the file download.php:
// get variables
$saveName = stripslashes($_GET["name"]);
$savePath = stripslashes($_GET["path"]);
// send headers to initiate a binary download
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$saveName");
header("Content-Transfer-Encoding: binary");
header("Content-length: " . filesize($savePath));
// read file
readfile($savePath);
?>
No comments:
Post a Comment