public function id(Silex\Application $app, $identifier) { $request = new \Flow\Request(); $path = utils::realpath(__DIR__ . "/../data/{$identifier}.json"); if ($path === false) { return new Response('', Response::HTTP_NOT_FOUND, ['Content-Type' => 'text/plain']); } $content = file_get_contents($path); $data = json_decode($content); $serverFile = utils::realpath($app->tmpDir("/{$data->name}")); if ($serverFile === false) { return new Response('', Response::HTTP_NOT_FOUND, ['Content-Type' => 'text/plain']); } $response = new StreamedResponse(function () use($serverFile) { //$file =fopen ($serverFile, "rb") ; //while ( !feof ($file) ) { // echo fread ($file, HttpRequest::max_chunk_size) ; // flush () ; //} //fclose ($file) ; @readfile($serverFile); }, Response::HTTP_OK, ['Cache-Control' => 'private', 'Content-Type' => 'application/octet-stream', 'Content-Transfer-Encoding' => 'binary', 'Content-Length' => filesize($serverFile), 'Content-Disposition' => "attachment; filename=\"{$data->name}\""]); //$contentDisposition =$response->headers->makeDisposition (ResponseHeaderBag::DISPOSITION_ATTACHMENT, $data->name) ; //$response->headers->set ('Content-Disposition', $contentDisposition) ; return $response; }