Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions en/controllers/request-response.rst
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,13 @@ You can accomplish that by using :php:meth:`Cake\\Http\\Response::withFile()`::
return $response;
}

// Prior to 3.4.0
$file = $this->Attachments->getFile($id);
$this->response->file($file['path']);
// Return the response to prevent controller from trying to render
// a view.
return $this->response;

As shown in the above example, you must pass the file path to the method.
CakePHP will send a proper content type header if it's a known file type listed
in `Cake\\Http\\Reponse::$_mimeTypes`. You can add new types prior to calling
Expand All @@ -509,6 +516,12 @@ the browser by specifying the options::
['download' => true, 'name' => 'foo']
);

// Prior to 3.4.0
$this->response->file(
$file['path'],
['download' => true, 'name' => 'foo']
);

The supported options are:

name
Expand Down