Today I came across an error that was not happening. When requesting a URI that returns an image via stream, the file comes “broken”.
//get photo
$this->get('/foto/{id}/{width}', function ($request, $response, $arqs) {
$id = $arqs["id"];
$width = $arqs["width"];
$Usuario = new UsuarioController;
$img = $Usuario->foto($id, $width);
if (file_exists(($img))) {
if ($fh = fopen($img, 'r+')) {
$stream = new \Slim\Http\Stream($fh);
//$stream = fpassthru($fh);
return $response->withBody($stream)
->withHeader("file", $img)
->withHeader("Content-Type", mime_content_type($img))
->withHeader("Content-Length", filesize($img));
}
}
});
is doing all the checks. and if the file exists then return. but