Hi,

Im building a download counter for my website. I have some Mp3's of my band and I want to keep track on how many times those mp3's have been downloaded.

My page is biult woth flash. I have a button that directs the user to:
download.php?file=song1.mp3

The download.php script checks the mysql database adds +1 download to that file and then it redirects using this code:

header("Location: " . $FILES_DIR . $file);

The problem is: That instead of that mp3 being downloaded it is opened in the webbrowser (with quicktime player), But I dont want this. I want the file being downloaded to the user's hard drive. The only solution I know for this problem is zipping the mp3's to have a 'song1.zip' file. But Im sure theres a better solution for this..

anyone knows???

Note: because my website is using flash, user CAN'T right clik the button to choose 'save target as'

    Hi,

    Have a look at headers, and how to use them. I believe that adding a
    header("Content-Disposition: attachment; filename=$filename");
    just before the file is send, should solve this.

    J.

      thankx for the reply, I think you are right, I must use that header or something similar. but after some testing I still Cant make this work....

      should I just put:

      header("Content-Disposition: attachment; filename=$file");

      replacing the:
      header("Location: " . $FILES_DIR . $file); ????

      How can I specify a path because files are not in the root...

      after putting that line a window opens asking if you want to save the file to disk but if you click 'save' it looks like the file downloads but it does not download. it just downloads a fake or imcomplete file. (107 bytes instead of 3 M😎

        you might want to try this:

                $file="some.mp3";
                //set the full path to the file
        	$fullPath="your/folder/to/mp3/" . $file;
        
        header("Content-Disposition: attachment; filename=".$file);
        readfile($fullPath);
        
          Write a Reply...