Jump to content
Larry Ullman's Book Forums

Counting Downloaded And Previewed Amont Belong To A Particular File In A Web Site

Recommended Posts


Im developing a web site to store a audio and video songs and it enable to download the songs for users. most of features I have finished at the moment. I need to count download users amount in a song and also need to count how many users view it only. actually I dont have any idea to do it using php. so anyone can me give any idea how to do it.

thanks in advance for your help....

Link to comment
Share on other sites

Thanks larry for your kindness help


but Im a begginer to php so no idea abt proxy scipt.. so is there any tutorial in your books, if it is so please let me know what is the book. PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition) with me bt there is no any discussion about the subject.

actually i need to count either how many people have downloaded a song offered by my web site or how many people have viewed. It is similar a feature that your this forum display 12 views, 13 views, 187 views etc for particular post...

I'm getting so frustrated abt this matter...

Link to comment
Share on other sites

Larry might correct me, but what I think he means is that when someone clicks the download link, a separate PHP script is called, which handles the download. Within that download script, you can also do whatever is necessary to increment a number in the database, etc.


As for viewing, well, it depends on what you define as "viewing". If simply going to a page and loading a song/video is "viewing", then incrementing the view/listen counter in the database each time the page is loaded would probably be sufficient.

Link to comment
Share on other sites

Ya, Hartley you are correct. I have created separate PHP script to handle audio/video songs. but I dont have any idea to do it in my download script. I have created a table called 'songs' to keep songs information, and there is a column named 'songs_name' to store songs name with it's extension. I dont sotore upload file's path in the database as well.

thanks in advance for any ideas...

Link to comment
Share on other sites

Well, that's exactly it, you need another script for downloading. For example, when a song is loaded for listening, you need to include a download link, which calls the download script. When that download script is called, you then update the download count in the database from the appropriate song, and serve the download to the user.


Does that make sense?

Link to comment
Share on other sites

In general, you'll put a download link next to the song/video that is being listened to/viewed, and when that link is clicked, the download script will be loaded with the necessary info sent via the GET method. Most likely, you'll just need the ID that corresponds to the song/video to get the proper file.


Then, from the download script itself, you need to do two things:

1) Allow the user to download the file.

2) If the download is successful, increment the counter in the database.


For the first part, there are a lot of PHP download scripts out there for free. The basic concept is that you see the Content-Disposition attribute to attachment via the header function, and then echo the file. The following is a decent script I found to do just that:




After then, you should verify that the file could be properly downloaded completely, and then make a call to the database to increment the "downloaded" counter by one. Again, because you should already have the ID for the song/video, just add 1 to the "downloaded" value in the DB for the song/video of the corresponding ID.


Does that help?

Link to comment
Share on other sites

Dear HartelySan, I tried simply adding a new field to the songs table used update query like this


update `songs` set songCounter = songCounter +1 where songID = '$sid'


It is work for me but it donsent mean down-loader actually finished the downloads ( it can cancel mid-way). Nevertheless my database table's fieldincrement by one. Is there any way to only count finish downloads.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...