6 Replies - 1073 Views - Last Post: 27 December 2012 - 04:34 AM

#1 olibenu  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 45
  • View blog
  • Posts: 537
  • Joined: 31-December 08

how to count number of times file has been downloaded

Posted 11 December 2012 - 06:15 AM

Hi DIC, it's been a while.

My question is about how DIC implements a utility.

If you notice, anytime you attach a file in a DIC topic,

it shows some stats as to how many people have downloaded the file.

Something like a counter as seen in this

old post of mine.

Any idea how this is done? Either DIC's implementation or some other one

where an incrementing count of downloads can be displayed next to a file link

This post has been edited by Dormilich: 11 December 2012 - 06:19 AM


Is This A Good Question/Topic? 0
  • +

Replies To: how to count number of times file has been downloaded

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,049
  • Joined: 08-June 10

Re: how to count number of times file has been downloaded

Posted 11 December 2012 - 06:17 AM

Id say, D.I.C. saves the number of file requests in a DB. (at least Id do that)
Was This Post Helpful? 0
  • +
  • -

#3 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,595
  • Joined: 16-October 07

Re: how to count number of times file has been downloaded

Posted 11 December 2012 - 06:54 AM

The file itself usually has a collection of meta data. Look at the link:
http://www.dreamincode.net/forums/index.php?
   app=core
   &module=attach
   &section=attach
   &attach_id=22210



You don't see "Jabberwocky.txt" in there. Chances are, in some directory not even exposed to HTTP, probably called attach, is a file called 22210. The name itself would be stored in a database. Some names are hacks to certain file systems, so it's easier just to ditch them as an actual name. Also, a good number could be called the same thing, e.g. main.cpp.

So, you click on the link and index.php does a database lookup on that id. It validates its availability, streams the file to you, and increments the ticker in the process.

Raw files on a CMS are messy. While DIC seems home grown, there are still some practices that make universal sense.
Was This Post Helpful? 1
  • +
  • -

#4 olibenu  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 45
  • View blog
  • Posts: 537
  • Joined: 31-December 08

Re: how to count number of times file has been downloaded

Posted 11 December 2012 - 07:45 AM

Thanks guys. I was afraid of this: db's and other heavy stuff.

I'd thought it would be something I can drag and drop.

Or a few lines in php.

Anyway, thanks. I'd have to do the research and implement it.

No free lunch on this one
Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,595
  • Joined: 16-October 07

Re: how to count number of times file has been downloaded

Posted 11 December 2012 - 08:21 AM

First, if you're going to work with any kind of website development, you MUST understand databases. It mightn't even be a SQL database, but the need for server side persistence is unavoidable.

On the other hand, you don't always need a sledge hammer when a simple nail driver will do.

Do you have code that allows the user to download a file via a PHP page. Do they just click on another link, or does the PHP handle the click? You could simply have a text file with the count. You could have a private little sqlite database. You could have a PHP object that you load and save via serialization.

There are many, many ways to persist data on a web site. Databases are popular for a reason. Don't avoid them because you feel they might be hard. If you think "that's too hard" then you've already defeated yourself. Think instead "I can figure this out." Works much better.
Was This Post Helpful? 1
  • +
  • -

#6 olibenu  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 45
  • View blog
  • Posts: 537
  • Joined: 31-December 08

Re: how to count number of times file has been downloaded

Posted 27 December 2012 - 12:36 AM

I later set up bit.ly on a subdomain. It's not exactly what I had in mind but it is a quick hack. Also YOURLS will do the same
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,435
  • Joined: 23-August 08

Re: how to count number of times file has been downloaded

Posted 27 December 2012 - 04:34 AM

Quote

While DIC seems home grown

Not home-grown, it's a commercial forum software package.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1