php - cakephp file download link -


i've encountered problem i'm trying solve more 2 days now: i've built website using cakephp , working fine got stuck when tried implement download links files stored under app_dir/somefolder/somefile.zip.

how set download links files inside somefolder? stumbled on "media views" tried implementing them far i've been unsuccessful.

besides there no easier way make files downloadable?

media views deprecated since version 2.3. should use sending files instead.

check out minimal example in controller:

public function download($id) {     $path = $this->yourmodel->amagicfunctionthatreturnsthepathtoyourfile($id);     $this->response->file($path, array(         'download' => true,         'name' => 'the name of file should appear on client\'s computer',     ));     return $this->response; } 

the first parameter of $this->response->file relative app directory. calling $this->response->file('somefolder' . ds . 'somefile.zip') download file app/somefolder/somefile.zip.

“sending files” requires @ least cakephp version 2.0. please consider taking @ cookbook link above.


if running older version of cakephp should use media views mentioned in question. use code , refer media views (cookbook).

here's same method older versions:

public function download($id) {     $this->viewclass = 'media';     $path = $this->yourmodel->amagicfunctionthatreturnsthepathtoyourfile($id);     // in example $path should hold filename trailing slash     $params = array(         'id' => 'somefile.zip',         'name' => 'the name of file should appear on client\'s computer',         'download' => true,         'extension' => 'zip',         'path' => $path     );     $this->set($params); } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -