Wednesday, January 18, 2012

how to count downloads

i want to know how to count when someone click to download some file..

important notice.. i don't store my files in database..i store it into
webroot/files

and i use meioupload to upload files


CREATE TABLE IF NOT EXISTS `downloads` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`filename` varchar(50) NOT NULL,
`title` varchar(70) NOT NULL,
`type` varchar(150) NOT NULL,
`filesize` int(11) unsigned NOT NULL,
`counts` int(11) NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;


{{{

downloads_controller.php


<?php
class DownloadsController extends AppController {
var $helpers = array ( "Html", "Ajax", "Javascript" ,"Number");
var $name = 'Downloads';
var $paginate = array('limit' => 3, 'page' => 1, 'order' =>
array('Download.id'=>'desc'));

function index() {
$this->set('downloads', $this->paginate());
}
}
?>

downloads/index.ctp


<?php
$i = 0;
foreach ($downloads as $download):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td>

<?php
$title = $download['Download']['title'];
$filename = '/files/'.$download['Download']['filename'];
echo $this->Html->link($title, $filename,array('escape' => false));

?>

</td>

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: