yeah i think it is pretty close.
it is a separate file all by itself. if the user clicks a link their browser will attempt to fetch the page and see that its just trying to get it to dl content so they will actually still be seeing the same page they clicked the link from, they will just get a save as dialog.
the header() calls are actually php code so there is no need for the <?php echo... parts inside. you can just use the variables directly like
header("Content-disposition: attachment; filename=$song_title.mp3");
the file_get_contents and the filesize functions will take the actual mp3 filename as it is on disk, not the $song_title one, the filename= part will tell the browser what to save it as. those functions should point to the location of the file on disk.
after the file get contents part you can just do another mysql_query() doing the update statement to increment the count.
in all it should be a short script, not too much longer than what you have.
i found this script i wrote a while back that i made as part of a file dump where people could upload files and stuff onto a main page and it counted download similar to what you are doing. the main difference is that i actually stored the binary file data in the database. but this should still be useful.
<?php
if(!isset($_GET['postid'])) {
echo "No file ID specified";
exit;
}
$postid = $_GET['postid'];
include("./config.inc.php");
dbconnect();
$query = "SELECT * FROM ${dbpref}dump WHERE postid = '$postid'";
$result = mysql_query($query);
$data = mysql_fetch_object($result);
if(!$result) {
echo mysql_error();
}
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$data->filename");
header("Content-Length: " . strlen($data->filedata));
echo $data->filedata; //output file data
//here i actually used a cookie to prevent counting a user downloading the same file twice but its optional
if(!isset($_COOKIE['download_' . $postid])) {
$cupdate = "UPDATE ${dbpref}dlcount SET count = count + 1 WHERE postid='$postid'";
$cupres = @mysql_query($cupdate);
$value = "downloaded";
@setcookie("download_" . $postid,$value,time()+31536000);
}
?>