I have followed Cakes Cookbook to send files (http://book.cakephp.org/3.0/en/controllers/request-response.html#sending-files) but I've been facing a weird problem. PDF's, DOC's and other binaries work just fine. But when I try to download/show an image (JPG or PNG) the file corrupts itself.
The downloaded file is not recognized as an image. It has the exactly same size of the original one, but when I diff it they are completly different.
I couldn't find anything like at the internet related to cake so I hope you can help me!
The below code is my download action
public function arquivo($id) {
$file = $this->Arquivos->get( $id );
$this->response->file($file['filename'], ['download' => true]);
// Return response object to prevent controller from trying to render
// a view.
return $this->response;
}
Response headers:
Accept-Ranges:bytes
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Length:121000
Content-Type:image/jpeg
Date:Thu, 24 Nov 2016 16:17:49 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=100
Pragma:no-cache
Server:Apache/2.4.10 (Ubuntu)