cakePHP

I think what i am about to say may apply to other versions of cakePHP and most probably the most recent. I created a simple download counter for my app. It might be stupid but it works. I created an app to server files using the code below but it was working only on my development windows box.


//download file and keep track of its count
// @param $id is the id of File to download by getting the path attribute.
  
public function download($id) {
         if (!$id) {
            throw new NotFoundException(__('Invalid file'));
        }
        $file = $this->Files->get($id);     
  
            
        $this->Files->patchEntity($file, ['downloads'=>$file->downloads+1]);
        if ($this->Files->save($file)) {
            $this->Flash->success(__('Your file download should start soon.'));
            $this->response->file($file->path);
            //return $this->redirect(['action' => 'home', 'controller' => 'Pages']);
        }
        $this->Flash->error(__('Unable to download.'));
       
    }

` When i moved it to my linux server, it refused to work because of permission issues until i set the permission to the file to 644 or RW-R–R–. Perhaps someone will find that problem and will need a fix.

LEAVE A REPLY

Please enter your comment!
Please enter your name here