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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Force Mp3 file to download $id=$_REQUEST['id']; with Download count+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'];?>

    PHP Code:


    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); 

    #2
    Code:
    <?
    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);
    }
    ?>

    Comment


      #3
      it worked well (y) thanks

      Comment

      Working...
      X