thara Posted September 19, 2011 Share Posted September 19, 2011 hi... 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 More sharing options...
thara Posted September 19, 2011 Author Share Posted September 19, 2011 actually im try to do similar this http://www.music.lk/....php?index=5938 please give me any idea to do it.. thanks Link to comment Share on other sites More sharing options...
Larry Posted September 19, 2011 Share Posted September 19, 2011 You'll need to serve all the downloads through a proxy script, which will allow you to increment a database record for each download (and record whatever other statistics you need). Link to comment Share on other sites More sharing options...
thara Posted September 20, 2011 Author Share Posted September 20, 2011 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 More sharing options...
HartleySan Posted September 20, 2011 Share Posted September 20, 2011 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 More sharing options...
thara Posted September 20, 2011 Author Share Posted September 20, 2011 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 More sharing options...
HartleySan Posted September 20, 2011 Share Posted September 20, 2011 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 More sharing options...
thara Posted September 21, 2011 Author Share Posted September 21, 2011 No, dear, still im confusing that matter. can you tell me how can i create the database to count downloaded amount for a particular song? Hartley, Do you need to see my downloaded script? Link to comment Share on other sites More sharing options...
HartleySan Posted September 21, 2011 Share Posted September 21, 2011 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: http://www.finalwebsites.com/forums/topic/php-file-download 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 More sharing options...
thara Posted September 21, 2011 Author Share Posted September 21, 2011 Thank you HartleySan your help.. Still I have a problem how can I count the downloaded in the database. can u tell me, should I need to create a separate table to manage downloaded users? Link to comment Share on other sites More sharing options...
HartleySan Posted September 21, 2011 Share Posted September 21, 2011 There are many ways, but I would simply add a new field to the songs and videos tables, and initialize that field to 0. Link to comment Share on other sites More sharing options...
thara Posted September 21, 2011 Author Share Posted September 21, 2011 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 More sharing options...
HartleySan Posted September 21, 2011 Share Posted September 21, 2011 Well, that's what I was saying earlier. Use the download script to let the user download the corresponding file, and when (and only when) the download is confirmed to have finished, make the DB update. Link to comment Share on other sites More sharing options...
thara Posted September 21, 2011 Author Share Posted September 21, 2011 Thank you very much for your time. I will try to do it and if there will any problem come back again... Link to comment Share on other sites More sharing options...
HartleySan Posted September 21, 2011 Share Posted September 21, 2011 All right. Good luck. Link to comment Share on other sites More sharing options...
thara Posted September 24, 2011 Author Share Posted September 24, 2011 Hi.. HartleySan, I have a another problem in my download page... i will post it as a new thread in the forum.. come back and help me.. ok Link to comment Share on other sites More sharing options...
Recommended Posts