It is more simple than in cakephp 1.3.
After 2.3, you only need to put the command bellow on action of your controller.
$this->response->file('/full_path/to/yourfile.jpg');
return $this->response;
Rodrigo Mourão
Webjump internet & social media
Rua Prof. Artur Ramos, 241 • conj. 52 • SP
Fone (11) 2338.6889
2013/4/14 Muhammad Asyraf <asyraf1985@gmail.com>
Actually, im on CakePHP 2.3...i read the documentation but confused on how to implement it. Sorry, im totally new with CakePHP..
On Monday, April 8, 2013 11:41:10 PM UTC+8, Muhammad Asyraf wrote:Based from tutorial at http://www.tuxradar.com/content/cakephp-tutorial-build-file-sharing-application , i manage to upload file and it capture the filename, filesize and filemime without any error but when download the file, it will produce wrong file mime for example, the file mime should be .jpg but in Google chrome it will be .htm and in IE it only download file with the name but no extension for that file. it seem something wrong with the controller codes.--function download($id = null) {if (!$id) {$this->Session->setFlash(__('Invalid id for upload', true));$this->redirect(array('action' => 'index'));}$this->Upload->bindModel(array('hasOne' => array('UploadsUser')));$upload = $this->Upload->find('first', array('conditions' => array('Upload.id' => $id,'OR' => array('UploadsUser.user_id' => $this->Auth->user('id'),'Upload.user_id' => $this->Auth->user('id'),),)));if (!$upload) {$this->Session->setFlash(__('Invalid id for upload', true));$this->redirect(array('action' => 'index'));}$this->viewClass = 'Media';$filename = $upload['Upload']['filename'];$this->set(array('id' => $upload['Upload']['id'],'name' => substr($filename, 0, strrpos($filename,'.')),'extension' => substr(strrchr($filename,'.'), 1),'path' => APP.'uploads'.DS,'download' => true,));}Based on the codes, maybe the extension have problem. Anyone can help? thanks...
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 a topic in the Google Groups "CakePHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cake-php/qv_ARaVAU4Q/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment