So I have a login secured area of my website where members can download files. The file is stored in a DB table and in that table has a "Download Count" column. On my page I display a link to download the file. When that link is clicked, I want to update the "Download Count" column in the database to reflect the increase in downloads.
I’m just really not sure how to accomplish this from a link being clicked, unless I just have to give it a form button to call to the update script along with the download?
link to something like
http://yoursite.com/downloadCounter.php?file=fileToDownload.zip
downloadCounter.php script increments some value in mysql database, then read file to buffer, and output the file with the proper header. It will appear to the same as clicking a standard file link.
Info on how to read the file:
Info on how to output the file(content type will depend on your filetype):
If the file is too big to work with this method you could probably do something similar with htaccess redirects.
would be a simple update statement to mysql depending on what your table structure looks like.
Sorry, a reference to the location of the file
what ever your download count column is +1
UPDATE whatever WHERE downloads = downloads+1
also, storing files in a db sucks ass. just add the name of the file to the row and link to it externally.
|
what ever your download count column is +1
UPDATE whatever WHERE downloads = downloads+1 also, storing files in a db sucks ass. just add the name of the file to the row and link to it externally. |
real helpful. i especially liked the part where you corrected me. faggot.
He’d already said that he just stores a reference to it.
|
what ever your download count column is +1
UPDATE whatever WHERE downloads = downloads+1 also, storing files in a db sucks ass. just add the name of the file to the row and link to it externally. |
UPDATE nameoftable SET downloads=downloads+1 WHERE fileid=123
….. <— seriously people
|
UPDATE nameoftable SET downloads=downloads+1 WHERE fileid=123 ….. <— seriously people |
Yes, I’m aware of what the SQL would be, just wasn’t sure if there was a way to do it from a link without sending it to a "download.php" to handle everything.
What about parsing the server logs? For counting downloads that’s as accurate and reliable as it gets.
I’m already doing it in the way mentioned above… all downloads routed through download.php, within there it starts the download for the file named in the passed variable and updates the database.