5

I am a beginer in programming. i have a pdf file for download in my website. I want to know the no. of downloads. I searched in google.

and i tried something like this. http://tutorialzine.com/2010/02/php-mysql-download-counter/

But everything is with database. Since i am a beginer, i am not familiar with database.

could you please suggest me the php code for this without database

vani
  • 53
  • 1
  • 1
  • 4
  • You could write some simple file handling code and store the count in a text file. PHP Manual has very good resources about it. http://www.php.net/fwrite – Hanky Panky Jun 01 '13 at 16:54

4 Answers4

9

if you are not familiar with database, try something like this

http://www.kavoir.com/2010/05/simplest-php-hit-counter-or-download-counter-count-the-number-of-times-of-access-visits-or-downloads.html

it may help you

geovani075
  • 369
  • 1
  • 2
  • 12
1

Well instead of a database you will have to keep a file with count

in the php file that downloads the pdf:

$downCount = intval( file_get_contents("/some/path/downloadCount") );
$downCount++;
file_put_contents("/some/path/downloadCount",$downCount);
Patrick Evans
  • 41,991
  • 6
  • 74
  • 87
0

PHP can't do it alone. It would need either a database, or an empty file to save to of some sort.

The best way is to use a database. Its probably the most easiest way as well. However I'd highly recommend getting in some database experience if you want to use PHP. Although database design / usage is very different to PHP, its very useful to know

Phil Cross
  • 9,017
  • 12
  • 50
  • 84
0

You could use the atime (access time) of the file as a counter aswell.

Alix Axel
  • 151,645
  • 95
  • 393
  • 500