Let’s say that Configure::read('App.uploads_temp')
is somewhere outside the public accessible directory: /var/www/yourapp/private
//This goes into the controller /** * @param $filename A filename without the path. EG: default-guy.jpg */ public function downloadimage($filename) { $file_parts = pathinfo($filename); $this->viewClass = 'Media'; $params = array( 'id' => $filename, 'name' => $file_parts['basename'], 'download' => false, 'extension' => $file_parts['extension'], 'path' =>Configure::read('App.uploads_temp'). DS ); $this->set($params); } |
You can view the image through the URL:
http://yourapp.com/entries/downloadimage/sample-image.jpg |
Reference: http://book.cakephp.org/2.0/en/views/media-view.html