How to Download Files in Cakephp?

Asked

Viewed 421 times

0

I have the path to a saved image in my bank. I would like to put a button in my view to download that image. How to do?

  • I’m not sure how I would do with cakephp but in case I could use a header: http://pastebin.com/r805nDX0 I used this to force the download of an XML file in my database.

1 answer

2


You can use the method file() of the object sponse for that. So:

$this->response->file(
    $file['path'],
    array('download' => true, 'name' => 'foo')
);
  • I’ll put this on the view?

  • You put in the controller, since the object sponse is inherited from the class Controller of own Cake.

  • And in the view as I put?

  • It depends on the method you will deploy. Simply put, you need to create a link in your View pointing to a function in your controller. In this controller you implement this code to download the file.

  • 1

    Thank you very much, it worked here. I created an action with your code and in the view I appended to this actions.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.