Friday, June 20, 2014

CakePHP download function returns 'empty' file

Help me, please, to resolve my small problem! I have next function in my PostsController:

public function download() {      if (isset($this->request->query['file']) && is_file(POST_ATTACH_PATH . $this->request->query['file'])) {          $file = $this->request->query['file'];          $output_name = 'up_free_' . rand();            $this->response->file(POST_ATTACH_PATH . $file, array(              'download' => true, 'name' => $output_name          ));            return $this->response;      } else {          $this->redirect(array('controller' => 'posts', 'action' => 'index'));      }  }

The problem is that my download function returns me 'empty' file! For example, if I have attached an image to the post and click the download button, my image downloads! But downloaded file is 'empty', I can't open it and if it is .jpg file it has the size of 132 KB.

Thank You!

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: