Force Mp3 file to download $id=$_REQUEST['id']; with Download count+1

Started on the old forum in November 2020 · view the original in the archive · old links redirect here

2 replies · 49 views · started 6 years ago · 1 min read

2 participants
ayesham Developer · 69 posts #1

in my mp3 downloading site script i need to put downloading button which function ( get.php?id=<?php echo $row['id'];?>')

so i would like to know how can i get mp3 downloading where id=$id with download count +1 each time download button hit.

Mp3 url = <?php echo $row['path'];?> downloads = <?php echo $row['dcount'];?>

 

include('db.php');

$id=$_REQUEST['id'];
$query = "update files SET views = views+1 where id ='".$id."'";
$update = mysqli_query($con,$query) or die(mysql_error());
$query = "SELECT * from files where id='".$id."'";
$result = mysqli_query($con,$query) or die(mysql_error());
$row = mysqli_fetch_assoc($result);
something else Fellow · 2,296 posts #2
<?
include('db.php');
$id=$_REQUEST['id'];
$query = "update files SET views = views+1 where id ='".$id."'";
$update = mysqli_query($con,$query) or die(mysql_error());
$query = "SELECT * from files where id='".$id."'";
$result = mysqli_query($con,$query) or die(mysql_error());
$row = mysqli_fetch_assoc($result);

$file_path = $row['path'];
$file_name = basename($file_path);

if (!is_file($file_path)) {
die("mp3 does not exist.");
}

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: audio/mpeg");
header("Content-Disposition: attachment; filename=\"$file_name\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($file_path));

$file = @fopen($file_path,"rb");
if ($file) {
while(!feof($file)) {
print(fread($file, 1024*8));
flush();
if (connection_status()!=0) {
@fclose($file);
die();
}
}
@fclose($file);
}
?>
ayesham Developer · 69 posts #3

it worked well (y) thanks 8)

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close